JSON 对象变为“null”;
我的 html5 Web Worker 一直遇到问题。 Web Worker postMessage() 是调用该 Worker 的文档级 JavaScript 的 JSON 对象,该对象附带一个 onmessage() 函数。
显然,“iterationsjob”键可以被访问,因为工作人员可以处理关联的数值,但这似乎只在 Google Chrome 中有效,并且仍然会引发错误:
18Uncaught TypeError: Cannot read property 'iterationsjob' of null
在 Firefox 中,网络工作人员根本不工作,并且不工作似乎也能够访问这些数字,我获得了成功的 ajax 调用,但它似乎绕过了日志记录步骤并通过单独的 ajax 调用引发了另一个错误。 因此,我编写了一种基本方法,让工作人员将 log() 消息发送回控制台,并从工作人员内部调用它们:
var iterations
//get iteration data from the server
p.ajax.post({
url:'/getdataurl',
dataType: "json",
success: function(responseText){
log("test");
log("responseText is "+responseText);
iterations = responseText.iterationsjob;
log("iterations is "+iterations);
}
});
我希望看到以下内容:
test
responseText is [object Object]
iterations is 3993547
相反,我看到:
test
responseText is [object Object]
iterations is 3993547
test
responseText is null
Uncaught TypeError: Cannot read property 'iterationsjob' of null
有人能解释一下问题是什么以及如何解决吗它? 编辑:我已经在此处上传了源代码的zip。在 Google App Engine 上运行。
谢谢!非常感谢任何帮助。
I've been having trouble with my html5 web worker. The web worker postMessage()'s a JSON object to the document-level javascript that invoked the worker, which comes with an onmessage() function.
Apparently the "iterationsjob" key can be accessed as the worker can process the associated number value, but this seems to only work in Google Chrome and it still raises the error:
18Uncaught TypeError: Cannot read property 'iterationsjob' of null
In Firefox, the web worker does not work at all and doesn't seem to be able to access the numbers either, I'm getting a successful ajax call but it seems to bypass the logging steps and raise another error with a separate ajax call.
So I hacked together a basic way for workers to log() messages back to the console, and invoked them from within the worker:
var iterations
//get iteration data from the server
p.ajax.post({
url:'/getdataurl',
dataType: "json",
success: function(responseText){
log("test");
log("responseText is "+responseText);
iterations = responseText.iterationsjob;
log("iterations is "+iterations);
}
});
I expected to see the following:
test
responseText is [object Object]
iterations is 3993547
Instead, I see:
test
responseText is [object Object]
iterations is 3993547
test
responseText is null
Uncaught TypeError: Cannot read property 'iterationsjob' of null
Could anybody explain what the problem is and how to fix it?
EDIT: I've uploaded a zip of the source code here. Runs on Google App Engine.
Thanks! any help much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊,原来我需要在第二个 ajax 调用中添加一个空的成功回调函数。由于某种原因,如果没有定义,它默认调用第一个成功回调...
Ah, turns out that I needed to add an empty success callback function to the second ajax call. for some reason it calls the first success callback by default if there is none defined...