简体   繁体   中英

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 .

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.

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 :

How can i solve this issue...

That site doesnt support the 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). 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);
          }
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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