ajax跨域的返回值如何输出
ajax跨域的返回值怎么输出
在我的getcookie.ashx页面中有如下代码:为了去调用getcookie()去获取服务器端的cookie
服务器端的en.js
GetCookie.ashx
而用alert()的方式是可以弹出来的
------解决方案--------------------
LZ先看看getJson中页面的url是否错误
再用firebug来调试看看 有没有收到回调的data值
------解决方案--------------------
用VAR 接了呢?
var link =data.link;
document.write(data.link); //为什么不会输出呢?
在我的getcookie.ashx页面中有如下代码:为了去调用getcookie()去获取服务器端的cookie
public void ProcessRequest(HttpContext context)
{
// context.Response.ContentType = "application/x-javascript";
context.Response.Write("<script src=\"Scripts/jquery-1.4.1.min.js\" type=\"text/javascript\"></script>");
context.Response.Write("<script src=\"http://192.131.0.18:80/jscript/en.js\" type=\"text/javascript\"></script>");
context.Response.Write("<script type=\"text/javascript\">");
context.Response.Write(" var a=GetCookie();");
context.Response.Write("document.write(a);");
context.Response.Write("</script>");
}
服务器端的en.js
function GetCookie() {
$.getJSON("http://192.131.0.18:80/ajax/GetCookie.ashx?jsoncallback=?", {},
function (data) {
document.write(data.link) //为什么不会输出呢?
});
}
GetCookie.ashx
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write(context.Request.QueryString["jsoncallback"]+ "({\"link\":\"" + HttpContext.Current.Request.Cookies["lan"].Value+ "\"})" );
}
而用alert()的方式是可以弹出来的
------解决方案--------------------
LZ先看看getJson中页面的url是否错误
再用firebug来调试看看 有没有收到回调的data值
------解决方案--------------------
用VAR 接了呢?
var link =data.link;
document.write(data.link); //为什么不会输出呢?