nilesh
nilesh

Reputation: 14287

Wait for AJAX to complete in Chrome

I am using something like following to wait for ajax request to complete in javascript. This works in IE and firefox but this is not working in Chrome. I really don't have any choice to use jQuery API since the automation tool I am using only supports execution of pure Java scripts. Is there anything I am missing here?

while(count!=0)
    count = jQuery.active;

Thanks, -Nilesh

Upvotes: 0

Views: 1460

Answers (2)

Ed Fryed
Ed Fryed

Reputation: 2198

$.ajax({
    type    :    "GET",     
    url     :    "url here",
    success :    function(html){
        complete(html);
    }
});

function complete(html){
    //do stuff when load complete here 
}

Not a very clear question. but here is a get ajax request with a 'complete' function.

Upvotes: 0

Tom
Tom

Reputation: 15940

As others have noted in the comments, your question really doesn't make sense but if you're looking to fire something off when an Ajax request has completed then you need to setup a callback function.

Assuming that you're using jQuery (which I can't tell from your question if you are or aren't), then you'd do this:

$.get('your-url.html', function(data) {

   // Your callback function.
   // Any word you need done after the response
   // has completed goes here.

});

If you need to do this in a post, then check out jQuery's $.post or even the $.ajax documentation.

If you're not using jQuery, then you can still achieve this using vanilla JavaScript, but you'll need to look at the XHR object order to determine if you're ready to fire the callback. All of that information is covered in-depth at the Mozilla Developer Center.

Upvotes: 1

Related Questions