English 中文(简体)
XMLHttpRequest
原标题:XMLHttpRequest leak

下面是我的javascript Code snippet。 它不像预期的那样运作,请帮助我这样做。

<script type="text/javascript">

   function getCurrentLocation() {
     console.log("inside location");
     navigator.geolocation.getCurrentPosition(function(position) {
       insert_coord(new google.maps.LatLng(position.coords.latitude,position.coords.longitude)); 
       });
   }

   function insert_coord(loc) {
     var request = new XMLHttpRequest();
     request.open("POST","start.php",true);
     request.onreadystatechange = function() {
                                     callback(request);
                                  };
     request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
     request.send("lat=" + encodeURIComponent(loc.lat()) + "&lng=" + encodeURIComponent(loc.lng()));

     return request;
   }

   function callback(req) {
     console.log("inside callback");
     if(req.readyState == 4)
       if(req.status == 200) {
         document.getElementById("scratch").innerHTML = "callback success";
         //window.setTimeout("getCurrentLocation()",5000);
         setTimeout(getCurrentLocation,5000);
       }
   }

getCurrentLocation(); //called on body load
</script>

试图实现的一点是,每5秒将我目前的位置送到综合系统网页。 i 在我的数据库中看不到几个坐标,但经过一段时间后,该坐标已经过。 火焰显示,像同时出现无规律的POST号一样,极具杂质。

https://i.imgur.com/xfViF.png“alt=“firebug Screenshot”/。

该系统在节目中出现泄漏。 请提供帮助。

EDIT:火焰虫的预期结果应当如此:

inside location
POST ....
inside callback

页: 1

inside location
POST ...
inside callback

页: 1

最佳回答

也许不是问题,但我可以建议两个因素:

取消两项要求:

if ((req.readyState == 4) && (req.status == 200)) {

你们可以缩短你的工作。 时间表:

setTimeout(getCurrentLocation, 5000);

为了解决该问题,我能否请你将规定时间从回击中删除,并用它来取代要求。 因此,你只字不提退时的“追捕成功”。

setTimeout(getCurrentLocation, 5000); //called on body load
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签