gpt4 book ai didi

javascript - 为什么我的 $.getJSON 可以工作但不执行 onsuccess 部分?

转载 作者:行者123 更新时间:2023-11-29 22:26:07 24 4
gpt4 key购买 nike

我有这个 Javascript:

var signUp = {
share: function(response) {
alert('hello');
}
}

$.getJSON("http://pgthatworks.com/?callback=?", {email:signUp.email, api:signUp.api, ref:signUp.ref}, function(response){
signUp.share(response);
});

$.getJSON() 一直工作到将数据发送到指定页面并且该页面正在执行它的工作,但是 function(response){} 部分不执行。知道为什么吗?

最佳答案

在我看来,您正在执行跨域请求。我这样说是因为您在 getJSON 请求中指定了完整的 URL 以及查询字符串中的回调参数。如果是这种情况,那么您的 PHP 需要发回正确的 JSONP。即:

print $callbackString.'('.json_encode($your_array).')';

关于javascript - 为什么我的 $.getJSON 可以工作但不执行 onsuccess 部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9205310/

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