gpt4 book ai didi

javascript - Json onLoad 有什么作用以及如何通过调用返回某些内容?

转载 作者:行者123 更新时间:2023-12-02 20:14:05 26 4
gpt4 key购买 nike

function JsonCall() {
JsonClient.setRequestHeader("Content-type", "application/json");
JsonClient.send(Data);
JsonClient.onload = function() {
SomeOtherFunction(this.responseText);
}
}

// This function is in someother class.

var Object = {
SomeOtherFunction: function() {
return data;
}
}
  1. 我的 JsonCall 函数是什么返回?
  2. 我可以做一些力所能及的事情吗从 onLoad 调用返回值Json 对象?

我想在其他类中执行一些逻辑并通过此 JsonCall 函数返回值

最佳答案

我觉得很奇怪。这里的 JsonClient 对象应该是一个 XHR 对象。但是,XHR 对象提供了 onreadystatechange 事件,通过检查 readyState 属性来处理完整的传输。

唯一的异常(exception)是来自 Internet Explorer 的 XDomainRequest 对象。该对象确实有一个 .onload 属性。现在,您的 JsonCall() 方法返回 undefined。您需要添加一个回调方法来执行。喜欢

function JsonCall( SomeOtherFunction ) {
JsonClient.setRequestHeader("Content-type", "application/json");
JsonClient.send(Data);
JsonClient.onload = function() {
SomeOtherFunction(this.responseText);
}
}

然后这样调用它

JsonCall( Object.SomeOtherFunction );

我希望Object只是这里的一个示例单词。

关于javascript - Json onLoad 有什么作用以及如何通过调用返回某些内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6569742/

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