gpt4 book ai didi

javascript - $.ajax 错误未捕获 SyntaxError : Unexpected token :

转载 作者:行者123 更新时间:2023-11-30 15:40:21 25 4
gpt4 key购买 nike

代码在coffeescript我正在尝试使用下面的代码(跨域)读取一个 json 文件

 $.ajax
url: 'https://canttypecompanyurlhere/books.json'
dataType: 'JSONP'
jsonpCallback: 'callback'
type: 'GET'
success: (data) ->
console.log (data)
error: () ->
console.log('error')

这是json

{ “名称”:“书1”, "author": "聪明人"

我做错了什么?我无法克服错误“uncaught SyntaxError: Unexpected token :”

请帮忙

最佳答案

您缺少包含 $.ajax 函数参数的括号,以及表示数据对象开头和结尾的大括号,更不用说对象定义每一行末尾的逗号了.它应该看起来像这样:

    $.ajax ({
url: 'https://canttypecompanyurlhere/books.json',
dataType: 'JSONP',
jsonpCallback: 'callback',
type: 'GET',
success: (data) -> {
console.log (data);
},
error: () -> {
console.log('error');
}
});

关于javascript - $.ajax 错误未捕获 SyntaxError : Unexpected token :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40919630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com