开发者

Wait for AJAX to complete in Chrome

开发者 https://www.devze.com 2023-02-15 21:30 出处:网络
I am using something like following to wait for ajax request to complete in javascript. This works in IE and fi开发者_如何学Crefox but this is not working in Chrome. I really don\'t have any choice to

I am using something like following to wait for ajax request to complete in javascript. This works in IE and fi开发者_如何学Crefox 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


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.


$.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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号