jquery的错误Twitter的搜索API [英] twitter search api with jquery error

查看:126
本文介绍了jquery的错误Twitter的搜索API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要请求Twitter搜索使用Twitter的API的jQuery。阅读后我写这篇code 文档:

I need to request a twitter search with jquery using twitter api. After read documentation I write this code:

  $.getJSON("http://search.twitter.com/search.json?callback=myFunction&q=stackoverflow");

   function myFunction(r) {
       console.log(r);
    }

search.json无法加载资源>当执行该页面,谷歌浏览器显示在控制台此错误:

search.json Failed to load resource> When the page is executed, Google Chrome show this error on Console:

XMLHtt prequest无法加载   <一href="http://search.twitter.com/search.json?callback=myFunction&q=stackoverflow">http://search.twitter.com/search.json?callback=myFunction&q=stackoverflow.   产地的http://本地主机/叽叽喳喳是不   通过允许   访问控制 - 允许 - 产地。   sea​​rch.json无法加载资源

XMLHttpRequest cannot load http://search.twitter.com/search.json?callback=myFunction&q=stackoverflow. Origin http://localhost/twitter is not allowed by Access-Control-Allow-Origin. search.json Failed to load resource

这是什么问题?

推荐答案

您需要在不同的写了一下,像这样的:

You need to write it a bit differently, like this:

$.getJSON("http://search.twitter.com/search.json?callback=?&q=stackoverflow", 
  function (r) {
    console.log(r);
});

要触发JSONP它寻找的明确回调=?,这是不是在你的命名函数的版本。要使用指定的回调,你最好的 $打算。阿贾克斯() 完整版:

To trigger JSONP it's looking for explicitly callback=?, which isn't in your named function version. To use the named callback, you're better off going with the $.ajax() full version:

$.ajax({
  url: "http://search.twitter.com/search.json?q=stackoverflow",
  dataType: "jsonp",
  jsonpCallback: "myFunction"
});

function myFunction(r) { console.log(r); }

这篇关于jquery的错误Twitter的搜索API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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