简体   繁体   English

jQuery ajax jsonp意外令牌:

[英]jQuery ajax jsonp unexpected token :

I am trying to get the data from third party http://api.bing.net/json.aspx?Appid=APPID&query=SEARCH_TERM&sources=Web&web.count=40&web.offset=41 . 我正在尝试从第三方http://api.bing.net/json.aspx?Appid=APPID&query=SEARCH_TERM&sources=Web&web.count=40&web.offset=41获取数据。

so i just used jsonp to get the data.I got the 200 status code.But i didn't get the resultant data on success.I also tried the callback it doesn't work. 所以我只是用jsonp来获取数据,我得到了200个状态码,但是我没有获得成功的结果数据,我还尝试了回调不起作用。

Attached my source code : 附上我的源代码:

    $.ajax({
      type : "GET",
      url : "http://api.bing.net/json.aspx?Appid=APPID&query=SEARCH_TERM&sources=Web&web.count=40&web.offset=41",
      dataType : "jsonp",
      success : function(data){
          console.log(data);
      },
      error : function(error) {
          console.log(error);
      }
    });

Error return in console : 在控制台中返回错误:

Uncaught SyntaxError: Unexpected token : 未捕获到的SyntaxError:意外令牌:

How can i solve this issue... 我该如何解决这个问题...

That site doesnt support the jsonp. 该网站不支持jsonp。 If it does, it should return the response with a call back function bind in it. 如果是这样,它应该返回响应,并在其中绑定一个回调函数。 ex: 例如:

callbackFun({"SearchResponse":{"Version":"2.2","Query":{"SearchTerms":"SEARCH_TERM"},"Errors":[{"Code":1002,"Message":"Parameter has invalid value.","Parameter":"SearchRequest.AppId","Value":"APPID","HelpUrl":"http:\/\/msdn.microsoft.com\/en-us\/library\/dd251042.aspx"}]}})

EDIT If you want to get that response to your client side. 编辑如果您想获得该答复给您的客户端。 Make your server act as a proxy to that site. 使您的服务器充当该站点的代理。 (Make an HTTP GET call from your server). (从服务器发出HTTP GET调用)。 And your client code will communicate to your server for the third party site's data. 您的客户代码将与您的服务器通信以获取第三方站点的数据。

your reponse seem to be valid,please try this 您的回复似乎有效,请尝试此操作

$.ajax({
          type : "GET",
          url : "http://api.bing.net/json.aspx?Appid=APPID&query=SEARCH_TERM&sources=Web&web.count=40&web.offset=41",
          dataType : "json",
          success : function(data){
              console.log(data);
          },
          error : function(error) {
              console.log(error);
          }
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM