"Uncaught SyntaxError: Unexpected token :" JSONP 响应



我向服务器发出JSONP请求,从中得到应用程序/json响应。

我的职能:

  function testJSONP(url) {
    $.ajax({
      url: url,
      jsonp: "callback",
      contentType: 'application/json',
      dataType: "jsonp",
      success: function (response) {
        console.log(response);
      }
    });
  }
在Chrome控制台中,

我收到以下错误消息,并且控制台中没有输出:

未捕获的语法错误: 意外令牌 :

我已经手动验证了我的 json 响应,没关系。

那么问题可能是什么呢?

尝试:

function testJSONP(url) {
    $.ajax({
      url: url,
      jsonp: "callback",
      contentType: 'application/javascript',
      dataType: "jsonp",
      success: function (response) {
        console.log(response);
      }
    });
  }

这样写...

function testJSONP(url) {
    $.getJSON(url,{},function(response){
        console.log(response);
    });
}

最新更新