i have a locate function defined in javascript
var locID;
function locateMe()
{
if(locID > 0)
{
// i do a jquery post here
}
setTimeout(locateMe, 2000);
}
// my document ready function is here, and inside it, at the end of it
// i do this
locID = 0;
locateMe();
when i test this code in firefox, the locateMe function is called every two seconds and works as expected. when i test the code in IE8 the function is never called (at least it appears to never be called from what i can see using IE's developer tools)
note: there is code defined in a click event handler for the 'zone_row' class that modifies locID. again, in firefox everything works as expected. the strange thing is, in IE when a zone_row is clicked the function WILL be called ONCE. i can see that both on the developer tools and through the result of the action of that jquery post.
i figured there is just some anomly with IE that i am not familiar with yet. what am i doing wrong?
EDIT: changed "locateMe();" to locateMe inside the setTimeout call.
UPDATE: adding more of my code (per request in ments) to show placement (albeit not much more code than my first post).
<script type="text/javascript">
var z_items;
var locID;
function locateMe()
{
if(locID > 0)
{
// my jquery post is here
}
setTimeout(locateMe, 2000);
}
$(document).ready(function()
{
// ... some click events and get requests here ...
locID = 0;
locateMe();
});
</script>
i also tried wrapping the call in a setTimeout (no effect) and changing the DOCTYPE (this actually caused IE to never call the function as opposed to now where it calls it ONCE and never again).
i have a locate function defined in javascript
var locID;
function locateMe()
{
if(locID > 0)
{
// i do a jquery post here
}
setTimeout(locateMe, 2000);
}
// my document ready function is here, and inside it, at the end of it
// i do this
locID = 0;
locateMe();
when i test this code in firefox, the locateMe function is called every two seconds and works as expected. when i test the code in IE8 the function is never called (at least it appears to never be called from what i can see using IE's developer tools)
note: there is code defined in a click event handler for the 'zone_row' class that modifies locID. again, in firefox everything works as expected. the strange thing is, in IE when a zone_row is clicked the function WILL be called ONCE. i can see that both on the developer tools and through the result of the action of that jquery post.
i figured there is just some anomly with IE that i am not familiar with yet. what am i doing wrong?
EDIT: changed "locateMe();" to locateMe inside the setTimeout call.
UPDATE: adding more of my code (per request in ments) to show placement (albeit not much more code than my first post).
<script type="text/javascript">
var z_items;
var locID;
function locateMe()
{
if(locID > 0)
{
// my jquery post is here
}
setTimeout(locateMe, 2000);
}
$(document).ready(function()
{
// ... some click events and get requests here ...
locID = 0;
locateMe();
});
</script>
i also tried wrapping the call in a setTimeout (no effect) and changing the DOCTYPE (this actually caused IE to never call the function as opposed to now where it calls it ONCE and never again).
Share Improve this question edited Feb 4, 2011 at 21:02 trh178 asked Feb 4, 2011 at 19:52 trh178trh178 11.7k5 gold badges29 silver badges38 bronze badges 5- 2 change setTimeout("locateMe()", 2000); to setTimeout(locateMe, 2000); first. – Sean Commented Feb 4, 2011 at 20:08
-
1
Actually,
setTimeout("locateMe()",2000);
works just fine for me (Win7 in FF3.6 and IE8). WhatDOCTYPE
are you using? Also, where is your code placed? Have you tried wrapping the firstlocateMe()
call in a timeout (maybe something is clobbering you during page load)? Last, replace yourif(locId>0){...}
withtestID++;test=document.getElementById("TEST");test.innerHTML=testID;
. – Brett Pontarelli Commented Feb 4, 2011 at 20:31 - hmmm... i did not consider DOCTYPE. it is set now as strict. bad idea? (<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "w3/TR/xhtml1/DTD/xhtml1-strict.dtd">) – trh178 Commented Feb 4, 2011 at 20:33
- @Brett - bingo! the testID suggestion was a great one. thats the kind of thing i never think of when 'debugging' internet stuff (bc im not used to this kind of programming). i did that and got a warning from IE8 about not running activeX controls. as soon as i hit 'allow blocked content' the testID started incrementing. – trh178 Commented Feb 4, 2011 at 21:11
- still not working. i assumed since Brett's ment worked that the POST would now work. it does not. i have both the counter and the POST in there. i can see the counter increase, indicating the function is actually being called. i dl fiddler to monitor traffic. i only ever see ONE post go out. just a note, i also displayed the locID below the counter. it is indeed the correct ID every time (i.e. NOT zero) so i should be getting into the if to send the post. im lost again now. im not sure how i can be calling the function with the correct locID and NOT send out the post?? – trh178 Commented Feb 7, 2011 at 13:19
3 Answers
Reset to default 2problem solved. i found an answer to another problem i was having from this post:
Prevent browser caching of jQuery AJAX call result
upon adding $.ajaxSetup({ cache: false }); to my document ready function, it solved THIS problem too. it looks like all this time it was a caching issue.
I've found that for IE (even IE9) that if you nest the self-called function in an anonymous function it works. But it does look like Toddeman's problem was related to the ajax part.
So the code would be:
function locateMe()
{
/* ... */
//IE way (still works in Chrome and FF):
setTimeout(function () { locateMe(); }, 2000);
//original: setTimeout(locateMe, 2000);
}
Use
setTimeout( locateMe, 2000 );
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745312937a4622083.html
评论列表(0条)