由网友(封尘M&M`S)分享简介:我需要从跨域获取JSON数据。$ .getJSON('HTTP:??//xx.xx.xx.xx/SampleService/Handler.ashx回调=',数据功能(jsonData){警报('1');}).done(函数(){执行console.log(第二个成功);}).fail(函数(){执行console.l...
我需要从跨域获取JSON数据。
$ .getJSON('HTTP:??//xx.xx.xx.xx/SampleService/Handler.ashx回调=',数据功能(jsonData){
警报('1');
})
.done(函数(){执行console.log(第二个成功);})
.fail(函数(){执行console.log(错误);})
。总是(函数(){执行console.log(完成);});
处理器code:
context.Response.ContentType =应用/ JSON;
SampleService服务=新SampleService();
名单<列表<字节>>响应= service.GetData();
串jsonData = JsonConvert.SerializeObject(响应);
context.Response.Write(的String.Format({0}([{1}]);,context.Request [回调],jsonData));
的错误,我得到的是:
parsererror
错误:jQuery19108131180874027861_1366004862133不叫
解决方案
好文章有关此问题:的跨域AJAX
I need to get the json data from the cross domain.
$.getJSON('http://xx.xx.xx.xx/SampleService/Handler.ashx?callback=?', data, function (jsonData) {
alert('1');
})
.done(function () { console.log("second success"); })
.fail(function () { console.log("error"); })
.always(function () { console.log("complete"); });
Handler code:
context.Response.ContentType = "application/json";
SampleService service = new SampleService();
List<List<Byte>> response = service.GetData();
string jsonData = JsonConvert.SerializeObject(response);
context.Response.Write(string.Format("{0}([{1}]);", context.Request["callback"], jsonData));
The error, I'm getting is:
"parsererror"
Error: jQuery19108131180874027861_1366004862133 was not called
解决方案
Good article about this issue: Cross Domain AJAX
相关推荐
最新文章