jquery ajax未捕获的SyntaxError:意外令牌:调用api时
I am trying to get a json response from the comicvine api but am getting the following error. comicvine.gamespot.com/:1 Uncaught SyntaxError: Unexpected token :
我正在尝试从comicvine api获得json响应,但是得到了以下错误。未捕获的SyntaxError:意外令牌:
I see my json result, formatted, in the response body but am getting the console error above.
我看到了我的json结果,格式化了,在响应体中,但是我得到了上面的控制台错误。
export function getSeriesFromComicVine() {
const url = "http://comicvine.gamespot.com/api/characters/?api_key=f18c6362ec6d4c0d7b6d550f36478c1cd6c04a49&filter=gender:male,name:hawkeye&format=json&callback=?";
$.ajax({
url: url,
// data: {test: "test"},
type: 'GET',
crossDomain: true,
jsonpCallback: 'callback',
dataType: 'jsonp',
jsonp: false,
jsonpCallback: "myJsonMethod"
success: function (data) {
console.log(data);
}
});
}
1 个解决方案
#1
2
You need to set format=jsonp
not json
您需要设置format=jsonp而不是json
the jsonp callback parameter name needs to be json_callback
according to comicvine.gamespot.com
- I found this out by going to url https://comicvine.gamespot.com/api/characters/?api_key=[your api key]&filter=gender:male,name:hawkeye&format=jsonp
in the browser, and it told me what was missing - very friendly API - the response had an error value
根据comicvine.gamespot.com, jsonp回调参数名称需要是json_callback——我通过url https://comicvine.gamespot.com/api/characters/?api_key=[您的api key]&filter=gender:male,name:hawkeye&format=jsonp在浏览器中,它告诉我缺少什么——非常友好的api——响应有一个错误值
"'jsonp' format requires a 'json_callback' arguement"
and no need for callback=?
in the url - seeing as jquery adds the callback parameter and it isn't named callback
不需要回调=?在url中——看到jquery添加了回调参数,它没有命名为callback
function getSeriesFromComicVine() {
const url = "https://comicvine.gamespot.com/api/characters/?api_key=[your api key]&filter=gender:male,name:hawkeye&format=jsonp";
$.ajax({
url: url,
type: 'GET',
dataType: 'jsonp',
jsonp: "json_callback",
success: function (data) {
console.log(data);
}
});
}
更多相关文章
- 在传递给google.setOnLoadCallback()的函数中使用参数;
- Js的Url中传递中文参数乱码,如何获取Url中参数问题
- 错误对象,本机和自定义,如何区分?
- Javascript setTimeout 带参数延迟执行 闭包实现
- 获取“RangeError:超出最大调用堆栈大小”错误
- 更新:在Gulpfile中带有postCSS和Babel的错误
- 如何使用jQuery在GET请求中传递参数
- JS之arguments 引发的一个错误
- 在javascript中调用带有双参数()的函数