views:

25

answers:

4

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.

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

+1  A: 

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.

Sarfraz
+1  A: 

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.

michael
A: 
Thiago Santos
Oops! ... typo. Its the extra curly brace.
siddharth178
A: 

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
  ); 
});
simplyharsh