使用jQuery获取http://imgur.com/gallery/hot/page/1.json [英] Get http://imgur.com/gallery/hot/page/1.json with jQuery

查看:91
本文介绍了使用jQuery获取http://imgur.com/gallery/hot/page/1.json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我尝试使用$ .getJSON和$ .ajax(...)获取此json. 但什么都没有...

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

我总是有类似的错误 XMLHttpRequest无法加载 http://imgur.com/gallery/hot/page/1.json . Access-Control-Allow-Origin不允许使用原点my_ip.

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.

我也尝试获取jsonp请求,但是什么也没有.

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

有另一个错误 未捕获到的SyntaxError:意外令牌:

have enother error Uncaught SyntaxError: Unexpected token :

似乎可以通过此插件获取此json jquery.xdomainajax.js

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

推荐答案

这是我的解决方案,也许有人会有用的.

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>

这篇关于使用jQuery获取http://imgur.com/gallery/hot/page/1.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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