简体   繁体   English

意外的令牌:发出Ajax json获取请求时出错

[英]Unexpected token : error when making Ajax json get request

I'm trying to make a cross domain ajax request to deezer, a music streaming api... and I'm getting an "Uncaught SyntaxError: Unexpected token :" error. 我正在尝试向deezer(一种音乐流api)发出跨域ajax请求...,并且出现了“ Uncaught SyntaxError:Unexpected token:”错误。 I know it's because the data I'm getting back is not in proper json format, but I tried changing the datatype to 'json' from 'jsonp' and it's still not working...here's my request, any suggestions? 我知道这是因为我返回的数据格式不正确,但我尝试将数据类型从“ jsonp”更改为“ json”,但仍无法正常工作。这是我的要求,有什么建议吗?

$.ajax({
  url: "https://api.deezer.com/search?q=" + searchString + "&callback=?",
  dataType: 'json',
  jsonpCallback: 'callback',
  type: 'GET',
  success: function (data) {
    console.log(data);
 }
});

This is because you used unencoded second "?" 这是因为您使用了未编码的第二个“?” in your url after first "?", which using for separate get-string. 在您网址的第一个“?”之后,用于单独的get-string。 You need to remove this part of url + "&callback=?" 您需要删除url + "&callback=?"这一部分。 .

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

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