JQuery won't get json?

前端 未结 5 1562
一向
一向 2020-12-03 12:07

So I\'m trying to complete the simple task of getting json data from google, but this little bit of jquery code won\'t run. Will you please help me figure out why?



        
5条回答
  •  爱一瞬间的悲伤
    2020-12-03 12:18

    I had the same issue. Trying to get json from a server to wich I dind't had access (=> no JSONP).

    I found http://benalman.com/projects/php-simple-proxy/ Add the php proxy to your server and do the ajax call to this file.

    $.ajax({
       type: 'GET',
       url:'proxy.php?url=http://anyDomain.com?someid=thispage',
       dataType: "json",
       success: function(data){
          // success_fn(data);
       },
       error: function(jqXHR, textStatus, errorThrown) {
          // error_fn(jqXHR, textStatus, errorThrown);
       }
    });
    

    where proxy.php (the file from Ben Alman) is hosted in your domain


    Alternative (which I found to be second best to this): http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/

提交回复
热议问题