gpt4 book ai didi

javascript - 将 XMLHttpRequest 转换为 JSONP

转载 作者:行者123 更新时间:2023-11-30 10:56:11 26 4
gpt4 key购买 nike

帮助,我需要更改此代码以支持远程域访问:

document.write(url);
var http = getHTTPObject();
http.open("GET", url, true);
http.onreadystatechange = function() {
if (http.readyState == 4) {
parseData(http.responseText);
}
}
http.send(null);

最佳答案

在你的 js 中:

function goRemote(url) {
var script = document.createElement("script");
script.src=url;
document.body.appendChild(script);
}
function parseDate(json) {
// do your fun here.
}

在你返回的 js 中:

parseData({"foo": "bar"});

关于javascript - 将 XMLHttpRequest 转换为 JSONP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1306011/

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