jQuery ajax y la carga no se repetirán en Chrome o IE8

I've found other threads discussing .load and .ajax with Chrome and IE, but none with my particular problem.

I'm using the following code to call in a response from a servlet. The response should be 3 lines of text/html, but I can adjust to text/plain.

function checkProgress(){
    $.ajax({
        type: "GET",
        url: "/myServlet",
        success: function(result) {
            $('#data').text(result);
            setTimeout(checkProgress, 2000);
        }

    });​
}

The idea here is to pull in the value ever 2 sec. and display in a div.

<div id="status" style="display:none;">                
            <h3>Status</h3>                
                <p id="data"></p>
            </div>  

The problem that I am having is that this will only load 1 time in Chrome and IE8. FF will repeat the load and I can see the value changing in browser.

Other issues I have seen talk about this not working at all in Chrome and IE8, but mine does work. It just will not repeat the load.

I have also tried this with .load because I want to maintain any html formatting and have encountered the same problem. I'm willing to skip the formatting for now so I can get this to update.

¡Cualquier ayuda es muy apreciada!

EDITADO Researching Chrome a little more, I've found that it stops the ajax script when I submit the form. My page kicks off a rather lengthy servlet. I'm using the Ajax call to return status updates from the servlet. When I submit to start the servlet, the script that is running to report the status stops in Chrome. No errors. It just stops running.

This looks like a threading issue in Chrome. Is there a better way of doing this? Can I kick-off both the ajax and servlet at the same time with an onsubmit event?

preguntado el 09 de marzo de 12 a las 15:03

I employed a combination of both the first 2 answers below and it is now working in IE8. Chrome will still not repeat the update. Could my interval be too short and firing some security flag in Chrome? -

2 Respuestas

IE caches ajax requests. How about adding a random string along with the url to make it a new request every time ?

Set the cache property value to false. So jquery will add a unique timestamp to all requests so it wont be a cached response everytime.

function checkProgress(){

    $.ajax({
        type: "GET",
        url: "/myServlet" ,
        cache: false,
        success: function(result) {
            $('#data').text(result);
            setTimeout(checkProgress, 2000);
        }

    });​
}

respondido 09 mar '12, 15:03

Upon further testing, the cache was the problem in IE8. Chrome is still holding out on me, though. - Jeff

Tu codigo:

setTimeout(checkProgress, 2000);

Change it to, you missed ():

setTimeout(function(){
    checkProgress();
}, 2000);

respondido 09 mar '12, 15:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.