【问题标题】:In jQuery Ajax, dataType: jsonp gives "SyntaxError: unterminated string literal" while dataType:json works fine?在 jQuery Ajax 中,dataType: jsonp 给出“SyntaxError: unterminated string literal”,而 dataType:json 工作正常吗?
【发布时间】:2018-04-26 04:22:41
【问题描述】:

下面是使用 jsonp 的 AJAX 调用,我在控制台中得到“SyntaxError: unterminated string literal”。

this.API_DOMAIN 是第 3 方网站。因此使用 jsonp 进行跨域。然而,同样的 AJAX 与 dataType: json 一起工作得很好。

响应的描述包含控制台给出错误的 ''LIVE'“'

但为什么 dataType: 'json'dataType: 'jsonp' 不能正常工作?

可能是什么问题?

var ajaxlink = this.API_DOMAIN+'callJson.php';
$.ajax({
  url: ajaxlink,
  type: 'GET',
  data:{
    oauth_token: this.API_KEY,
    id:eventId,
    moreInfo:'artistinfo,booking,multiplebooking',
    lang:LANG_DEFAULT
  },
  jsonpCallback: "aaaaa",
  cache: true,
  dataType:"jsonp",
  success: function(data){
    console.log("similar event success");
    console.log(data);
  },
  error: function(){
    console.log("error");
  }
});

【问题讨论】:

  • 你试过 JSON.stringify 数据检查了吗?

标签: javascript jquery json ajax jsonp


【解决方案1】:

你的字符串是用单引号还是双引号分隔? 特殊字符应该被转义,如果它是多行连接加号或反斜杠符号。 var s = "这是一个很长的字符串\ 第二部分 od 字符串";

【讨论】:

    猜你喜欢
    • 2020-06-05
    • 1970-01-01
    • 2015-07-12
    • 1970-01-01
    • 2016-12-24
    • 2017-12-18
    • 1970-01-01
    • 2014-03-09
    • 1970-01-01
    相关资源
    最近更新 更多