gpt4 book ai didi

javascript - jQuery AJAX JSONP 错误 "Unexpected token"

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:36:26 25 4
gpt4 key购买 nike

我正在尝试在 Chrome 中进行跨域 JSONP 调用,但我一直返回 “未捕获的语法错误:意外的 token :”我已经尝试过:更改响应内容类型、设置 xhr header 、JSON.stringify,几乎这里提供的大多数解决方案,但到目前为止没有任何效果:-(

 $.ajax({
type: "POST",
url: "https://www.virustotal.com/vtapi/v2/url/report",
crossDomain: true,
contentType: "application/json; charset=UTF-8",
dataType: 'jsonp',
data: {
apikey: "*",
resource: "http://www.1001freefonts.com/font/BaroqueScript.zip"
},
jsonp: false,
jsonpCallback: receive,
success: function (data, textStatus, jqXHR) {
console.log("Data retrieved: " + data);
}
}).done(function () {
console.log('I think we are done here');
})
.error(function (e) {
console.log(arguments);
console.log('something went funny here');
})
.complete(function (xhr, status) {

console.log("complete");
if (status === 'error' || !xhr.responseText) {
console.log('error');
}
else {
console.log("data found:" + xhr.responseText);
//...
}
});
});

function receive(saveData) {
if (saveData == null) {
console.log("DATA IS UNDEFINED!"); // displays every time
}
console.log("Success is " + saveData); // 'Success is undefined'
}

在调试器中我可以看到响应

{"permalink": "https://www.virustotal.com/url/b5b546fdbb49a2258e951c5e568a52655c65ac56112e39d15af0954a53b36772/analysis/1360339512/", "url": "http://www.1001freefonts.com/font/BaroqueScript.zip", "response_code": 1, "scan_date": "2013-02-08 16:05:12", "scan_id": "b5b546fdbb49a2258e951c5e568a52655c65ac56112e39d15af0954a53b36772-1360339512", "verbose_msg": "Scan finished, scan information embedded in this object", "filescan_id": "b7e13c0242e9690aba1f3da4b73d9c2e99a9b7fd03f542b55e694a34aaf9eca8-1360339519", "positives": 0, "total": 35, "scans": {"CLEAN MX": {"detected": false, "result": "clean site"}, "MalwarePatrol": {"detected": false, "result": "clean site"}, "ZDB Zeus": {"detected": false, "result": "clean site"}, "K7AntiVirus": {"detected": false, "result": "clean site"}, "Quttera": {"detected": false, "result": "clean site"}, "Yandex Safebrowsing": {"detected": false, "result": "clean site"}, "MalwareDomainList": {"detected": false, "result": "clean site"}, "ZeusTracker": {"detected": false, "result": "clean site"}, "zvelo": {"detected": false, "result": "clean site"}, "Google Safebrowsing": {"detected": false, "result": "clean site"}, "BitDefender": {"detected": false, "result": "clean site"}, "Opera": {"detected": false, "result": "clean site"}, "G-Data": {"detected": false, "result": "clean site"}, "C-SIRT": {"detected": false, "result": "clean site"}, "Sucuri SiteCheck": {"detected": false, "result": "clean site"}, "VX Vault": {"detected": false, "result": "clean site"}, "ADMINUSLabs": {"detected": false, "result": "clean site"}, "SCUMWARE.org": {"detected": false, "result": "clean site"}, "Dr.Web": {"detected": false, "result": "clean site"}, "AlienVault": {"detected": false, "result": "clean site"}, "Malc0de Database": {"detected": false, "result": "clean site"}, "SpyEyeTracker": {"detected": false, "result": "clean site"}, "Phishtank": {"detected": false, "result": "clean site"}, "Avira": {"detected": false, "result": "clean site"}, "Antiy-AVL": {"detected": false, "result": "clean site"}, "Comodo Site Inspector": {"detected": false, "result": "clean site"}, "Malekal": {"detected": false, "result": "clean site"}, "ESET": {"detected": false, "result": "clean site"}, "SecureBrain": {"detected": false, "result": "unrated site"}, "Netcraft": {"detected": false, "result": "clean site"}, "ParetoLogic": {"detected": false, "result": "clean site"}, "URLQuery": {"detected": false, "result": "unrated site"}, "Wepawet": {"detected": false, "result": "unrated site"}, "Minotaur": {"detected": false, "result": "clean site"}}}

我已经在 http://jsonlint.com/ 上验证过了它表明它是一个有效的 JSON。

这是响应头

cache-control:no-cache
content-encoding:gzip
content-length:695
content-type:application/json
date:Wed, 13 Feb 2013 12:00:33 GMT
server:Google Frontend
status:200 OK
vary:Accept-Encoding
version:HTTP/1.1

有人有什么想法/建议吗?

最佳答案

经过全面测试后,很明显,当 ajax 期望 JSONP 返回时(由于跨域限制),无法捕获 JSON 对象结果。即使响应状态 = 200。

我一直在使用 jQuery AJAX 调用进行测试,试图查看是否仍然可以捕获结果 - 尽管浏览器抛出了解析错误 - 但似乎这不可能。看起来响应文本在 JS 工作完成后到达 header 。

正如@Florian F. @Likwid_T @Christoph 上面所建议的那样,服务器端脚本绝对需要使其正常工作。其他开发人员似乎热衷于使用用 C# 编写的代理作为解决方案。

关于javascript - jQuery AJAX JSONP 错误 "Unexpected token",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14853267/

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