
>在Safari iOS 2上,一切正常,直到我添加此代码:
var watchID = navigator.geolocation.watchposition(updatePos,locationError,{maximumAge: 10000,frequency: 60000,enableHighAccuracy: true,timeout: 1000});function updatePos(position) { if (position.coords.accuracy < accuracyThreshold) { $.post(websiteRoot + '/ReportDeviceLocation?rand=' + (Math.random() * Math.random()) + '&longitude=' + position.coords.longitude + '&latitude=' +position.coords.latitude); } else { console.deBUG("Location data is not accurate enough. Location not updated."); }} >然后网页工作了大约4分钟,我收到此错误:
JavaScript执行超过了超时.
>那么没有JavaScript会加载.我插入到my.Js文件中的调试消息都不会打印出来.只有上面的错误.
>即使在我离开生成此错误的页面并在同一域下打开其他网页后,错误仍然存在.
>我使用了try和catch,我使用了setTimeout函数,但是既没有给我错误的来源也没有解决问题.
我不知道问题是什么.它一整天都在燃烧我,并会在周末燃烧我.
解决方法 令人惊讶的是,当我使用geolocation.getCurrentposition时,错误消息停止显示.要用getCurrentposition替换watchposition,我使用函数setInterval:
function getLocation() { navigator.geolocation.getCurrentposition(updatePos,{ enableHighAccuracy: true,timeout: 10000 }); } var intervalID = window.setInterval(getLocation,10000); 这比watchposition效果更好,因为watchposition有时不遵循规则(尽管频率设置为10分钟,但在3分钟内更新位置8次).
如果仍然发生超时,则需要调用clearInterval:
var geolocationID;(function getLocation() { var count = 0; geolocationID = window.setInterval( function () { count++; if (count > 3) { //when count reaches a number,reset interval window.clearInterval(geolocationID); getLocation(); } else { navigator.geolocation.getCurrentposition(updatePos,timeout: 10000 }); } },600000); //end setInterval;})(); 总结 以上是内存溢出为你收集整理的JavaScript执行超过了超时全部内容,希望文章能够帮你解决JavaScript执行超过了超时所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)