有没有人使用带有PetFinder API URL请求字符串的jQuery.getJSON()遇到任何问题?

时间:2013-09-25 19:21:15

标签: jquery api

网址查询字符串以适当的格式给出了正确的答案,但我无法在网页上实现。

我尝试使用正确的GET参数执行下面的脚本进行测试,但它不会返回任何内容,甚至是警报。

我认为问题出在网址上,因为我试过https://graph.facebook.com/zombies 作为网址,它工作。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">

   $.getJSON('http://api.petfinder.com/pet.find?key=1234567890&location=&format=json', function(pet)  
    {      
           alert("hi!");
    });

</script>

有没有办法解决这个问题? 谢谢!

1 个答案:

答案 0 :(得分:0)

如果直接转到该URL,则会收到XML响应,告诉您使用的密钥1234567890无效。我认为这是您从他们的文档中获取的演示密钥,但通常使用API​​,您需要重新注册自己的应用程序,并在请求中使用应用程序API密钥。

结果XML

<petfinder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://api.petfinder.com/schemas/0.9/petfinder.xsd">
 <header>
  <version>0.1</version>
  <timestamp>2013-09-25T19:32:59Z</timestamp>
  <status>
   <code>300</code>
   <message>unauthorized key</message>
  </status>
 </header>
</petfinder>