GetJson()Ajax调用无法正常工作 [英] GetJson() Ajax call is not working properly

查看:61
本文介绍了GetJson()Ajax调用无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在尝试调用webservice方法并返回一个字符串。当我尝试使用 $。getJSON 尝试访问此方法时,我能够点击该方法,但即使我是从网络服务获取,但我无法进入下面的功能。我只是在控制台看着我得到回应...如果我使用ajax电话我正在考虑跨域问题...请帮助我.....



Hello,
I am trying to do a call to webservice method and it returns a string. when I try to access this methos using $.getJSON I am able to hit the method but even i am gettign resposnse from web service but I am unable to enter into below function . I am just watching in console that I am getting response... If I use ajax call i am geting cross domain issue... Please help me out .....

   $.getJSON('https://172.16.25.47/JsonPTestApp/clurcService.asmx/getRCjson?SPA=8353/1000/0140',  function (data) 
{
              alert("came inseide")
              var test = data;
              alert(test);
 });

推荐答案

.getJSON 我能够点击该方法,但即使我是从网络服务获取,但我无法进入下面的功能。我只是在控制台看着我得到回应...如果我使用ajax电话我正在考虑跨域问题...请帮助我.....



.getJSON I am able to hit the method but even i am gettign resposnse from web service but I am unable to enter into below function . I am just watching in console that I am getting response... If I use ajax call i am geting cross domain issue... Please help me out .....


.getJSON('https://172.16.25.47/JsonPTestApp/clurcService.asmx/getRCjson?SPA=8353/1000/0140' ,function(data)
{
alert(came inseide)
var test = data;
alert(test);
});
.getJSON('https://172.16.25.47/JsonPTestApp/clurcService.asmx/getRCjson?SPA=8353/1000/0140', function (data) { alert("came inseide") var test = data; alert(test); });


当源与目标地址/主机名不匹配且服务器未指定允许此行为时,会导致CORS(跨源资源共享)问题。对此的简单解决方案是使服务器(这种情况下为asmx服务)返回允许您的原点的标头。如果您有一个域名,您可以指定此域名,否则您只需指定*通配符即可允许所有来源。



我还没有写asmx之前我认为解决方案可能如下:



CORS (Cross Origin Resource Sharing) issues are caused when the origin does not match the destination address / host name and the server has not specified that this behavior is allowed. The simple solution to this is to make the server (this case a asmx service) return the header that allows your origin. If you have a domain you are running this from you can specify this domain, otherwise you need only specify the * wildcard to allow all origins.

I haven't written asmx before however i think a solution could look like :

Response.AddHeader("Access-Control-Allow-Origin","*")





希望这有帮助



Hope this helps


这篇关于GetJson()Ajax调用无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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