再次更新:此jQuery代码不起作用,为什么? [英] Again+Updated: This jQuery code doesn't work, Why?

查看:97
本文介绍了再次更新:此jQuery代码不起作用,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天早上我问了一个关于无法正常工作的jQuery代码的问题(它使用API​​捕获了json文件),然后一些很棒的人告诉我,必须在jsonp中包含json文件才能使用callback,而我没有.

I asked this morning a question about a jQuery code that's not working (which grabs a json file using API) then some great people told that I must have the json file in jsonp to use callback , which I wasn't have..

我与提供API的网站的开发人员进行了交流,他解决了该问题,使其支持jsonp,但是代码仍然无法正常工作!

I communicated with the developer of the website that provides the API and he solved the problem so that it supports jsonp, but still the code doesn't work !!

这是页面的代码(您可以在 http://rawaji的页面的源代码中看到该代码. com/test.html )

here is the code of the page (you can see it viewing the source of this page http://rawaji.com/test.html )

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<script src="http://code.jquery.com/jquery-latest.js"></script>
 <script>
  $(document).ready(function(){
    $.getJSON("http://api.qaym.com/0.1/countries/key=u2gTerCTZDudTCMhQBQ9&jsoncallback=?",
        function(data){
          $.each(data, function(i,item){
             $("#results").append("<span class='result' >" + item.name + "</span></br>");
            if ( i == 3 ) return false;
          });
        });
  });
  </script>

</head>
<body>
  <div id="results">
  </div>
</body>
</html>

请注意,FireBug告诉我代码中没有错误,甚至控制台也告诉我文件已正确导入(请参见此处的图像

just a little note, that FireBug tells me no errors in the code and even the console tells that the file imported correctly (see the image here http://twitpic.com/5yycg5 )

缺少什么! :(

更新:

我使用了另一个控制台,它向我显示了此消息!

I used another consoler and it shows me this message!

key = u2gTerCTZDudTCMhQBQ9& jsoncallback = jQuery16206894429267849773_1312140242381:-1 资源被解释为脚本,但以MIME类型传输 application/json.

key=u2gTerCTZDudTCMhQBQ9&jsoncallback=jQuery16206894429267849773_1312140242381:-1 Resource interpreted as Script but transferred with MIME type application/json.

我对此一无所知,但我会进行搜索.如果有人有主意,请告诉:)

I just know nothing about it, but I will search it. if someone has an idea, plz tell :)

推荐答案

这有效:

$(function(){
    $.ajax({
        url: 'http://api.qaym.com/0.1/countries/key=u2gTerCTZDudTCMhQBQ9',
        dataType: 'jsonp',
        crossDomain:true,
        success:function(data){
            $.each(data, function(i,item){
                $("#results").append("<span class='result' >" + item.name + "</span></br>");
                if ( i == 3 ) return false;
            });
        },
        error:function(jqxhr,err,status){
            alert(status);
        }
    });
});

返回的401错误要求进行身份验证-无效的API密钥.

The 401 error coming back requires authentication - invalid API key.

http://jsfiddle.net/AlienWebguy/CqrPe/

这篇关于再次更新:此jQuery代码不起作用,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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