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;
}
}
- 我的 JsonCall 函数是什么 返回?
- 我可以做一些力所能及的事情吗 从 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/