Get http://imgur.com/gallery/hot/page/1.json with jQuery

孤街醉人 提交于 2019-12-11 20:12:44

问题


Hello i try get this json with $.getJSON, also $.ajax(...) but nothing...

 jQuery.ajax({
                url: "http://imgur.com/gallery/hot/page/1.json",
                type: 'GET',                   
                crossDomain:true,
                success: succ
            });

always i have errors like XMLHttpRequest cannot load http://imgur.com/gallery/hot/page/1.json. Origin my_ip is not allowed by Access-Control-Allow-Origin.

also i tried get jsonp request but also nothing..

   jQuery.ajax({
                url: "http://imgur.com/gallery/hot/page/1.json",
                type: 'GET',
                dataType: 'jsonp',
                crossDomain:true,
                success: succ
            });

have enother error Uncaught SyntaxError: Unexpected token :

its looks like it is possible get this json with this plugin jquery.xdomainajax.js


回答1:


Here is my solution, maybe someone it will be usefull.

<script src="jquery.xdomainajax.js"></script>
<script>
   $(document).ready(function() {
            jQuery.ajax({
                url: "http://imgur.com/gallery/hot/page/1.json",
                type: 'GET',                 
                success: function(data){
                           //creating json object
                           var jsonResp=$.parseJSON($(data.responseText).text().trim());
                         }

            });   
  });
</script>


来源:https://stackoverflow.com/questions/8014504/get-http-imgur-com-gallery-hot-page-1-json-with-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!