+ -
当前位置:首页 → 问答吧 → $.getJSON 跨域问题

$.getJSON 跨域问题

时间:2010-12-22

来源:互联网

跨域获取Json问题,无法进入回调函数。

站一:http://localhost:4003
站二:http://localhost:4002

在站一下调用,可获取本地Json,跨域时需要加上"http://localhost:4002/WS/GetCustomer.ashx?jsoncallback=?"才能返回Json数据
JScript code

$.getJSON('http://localhost:4002/WS/GetCustomer.ashx?', function(json){
           alert(json.id)
});




GetCustomer.ashx代码如下
C# code

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("{\"id\":1}");
//context.Response.Write(context.Request["jsoncallback"] + "{\"id\":1}");
context.Response.Flush();
context.Response.End();


跨域的情况下,调试是显示有Json返回"{"id":1}",但始终进不去回调函数,IE里好像可以

作者: lucky313   发布时间: 2010-12-22

记得跨域的时候,ie里好像有个选项,“通过跨域访问数据源”,默认是禁用的,如果改为启用貌似就可以了。

作者: y_h_t   发布时间: 2010-12-22

IE下是可以访问噢,

只是在FireFox下不行。

使用FireBug查看,是有响应数据和Json的,就是进不了回调函数里

作者: lucky313   发布时间: 2010-12-22

谁来指点指点哟,就是getJSON,没法执行回调函数额。数据包能看到ashx返回的Json的

作者: lucky313   发布时间: 2010-12-22

热门下载

更多