2011-09-02 43 views
0

我一直遇到我的html5 web worker的麻烦。 web worker postMessage()是一个JSON对象,用于调用工作者的文档级别的JavaScript,它带有一个onmessage()函数。JSON对象变为'null'

显然,“iterationsjob”键可以作为工人可以处理相关的数值访问,但这似乎只在谷歌Chrome浏览器,它仍然引发错误:

18Uncaught TypeError: Cannot read property 'iterationsjob' of null 

在Firefox中,网络工作者根本无法工作,也似乎无法访问数字,我得到了一个成功的ajax调用,但它似乎绕过了日志记录步骤,并通过单独的ajax调用引发了另一个错误。 所以我砍死在一起,让工人数()信息返回到控制台一个基本途径,并从工人中调用它们:

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 

有人可以解释什么问题,以及如何解决它? 编辑:我已经上传了源代码here的zip。在Google App Engine上运行。

谢谢!任何帮助非常感谢。

+0

向我们展示问题的自包含测试用例,而不是散文。 –

+0

可能重复的[jquery蜂巢ajax调用不工作](http://stackoverflow.com/questions/7218297/jquery-hive-ajax-call-not-working) –

+0

哎呀,对不起。自从那篇文章以来,我已经取得了一些进展,并将问题分为两个独立的问题,所以我会投票去除该帖子。 – ejang

回答

0

啊,事实证明,我需要添加一个空的成功回调函数到第二个Ajax调用。由于某种原因,如果没有定义,它会默认称为第一次成功回调...