简体   繁体   中英

Prevent jQuery.ajax() from sending automatically

I need to do some (potentially asynchronous) stuff before sending an AJAX-request via jQuery. Is there any way to evoke the sending of the request on a jqXHR object manually? The problem is that I need to immediately return the jqXHR object (eg to use the $.Deferred() interface)

you can use beforeSend event in jQuery

 $.ajax({
      url: "url",
      beforeSend: function ( xhr ) {
      // you can do here 
      }
    }).done(function ( data ) {
     .............
    });

see here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM