跨域Ajax请求的问题 [英] Cross domain ajax request issue

查看:183
本文介绍了跨域Ajax请求的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从跨域获取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

这篇关于跨域Ajax请求的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆