开发者

jquery ajax call not able to see response data

Ajax response I am getting is always empty! Interestingly, if I copy paste that URL in browser, I do get a proper html snippet (test ad) back. I guess this is related to some cross-site call stuff. Need some help/pointers as response is not json. Its html code.开发者_StackOverflow中文版

Please look at the code - http://pastie.org/1120352


It looks you are fetching data from some different host.

You need to have a look at Same Origin Policy:

In computing, the same origin policy is an important security concept for a number of browser-side programming languages, such as JavaScript. The policy permits scripts running on pages originating from the same site to access each other's methods and properties with no specific restrictions, but prevents access to most methods and properties across pages on different sites.

For you to be able to get data, it has to be:

Same protocol and host

You need to implement JSONP to workaround it.


Yes, the problem is most likely cross-domain restrictions.

Can you state whether the web page itself is on the same domain and subdomain as the URL you are requesting (http://ads.admarvel.com/)?

If you are not on the same domain then you will need to make a request to a proxy script to grab the data.


Also, it seems like your code has an extra closing bracket and parentesis.

$(document).ready(function () { 
$.get(url,{}, function (d) {
        alert(d);
}

});

});


Also, try adding type attribute.

$(document).ready(function (){ 
  $.get(
     url: url,
     data: {}, 
     callback: function (d) {
        alert(d);
     },
     type: 'json' \\ or whatever the call is returning
  ); 
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜