title: AJAX : What is the equivalent function of beforeSend function in XMLHttpRequest
body: <p>In $.ajax there is beforeSend function, but now I'm trying to use XMLHttpRequest, I'm looking for equivalent function of beforeSend in $.ajax. How can i implement it in here.</p>
  
  <p>Here is my xhr code,</p>
  
  <pre><code>xhr = new XMLHttpRequest();
      var url = '../ajax/ajax_edit/update_ajax_staffUser.php';
  
      if(file.files.length !== 0){
  
          if(!check(fileUpload.type)){
              alert("This file format not accepted");
              return false;
          }
          xhr.open('post', url+param, true);
          xhr.setRequestHeader('Content-Type','multipart/form-data');
          xhr.setRequestHeader('X-File-Name', fileUpload.name);
          xhr.setRequestHeader('X-File-Size', fileUpload.size);
          xhr.setRequestHeader('X-File-Type', fileUpload.type);
          xhr.send(fileUpload);
      }else{
          xhr.open('post', url+param, true);
          xhr.setRequestHeader('Content-Type','multipart/form-data');
          xhr.send(fileUpload);
      }
  
  
      xhr.onreadystatechange = function(e){
          if(xhr.readyState===4){
              if(xhr.status==200){
                  $('.bounce_dim').show();
                  setTimeout(function(){
                      $('.trigger_danger_alert_changable_success').show().delay(5000).fadeOut();
                      $('#palitan_ng_text_success').html('User successfully modified');
                      $('#frm_edit_staffUser')[0].reset();
                      $('#modal_staff').modal('hide');
                      $('.bounce_dim').hide();
                  },1000);
                  getUserStaffTable();
              }
          }
      }
  </code></pre>
  
  <p>Since the users are uploading image to my web, I need to make a waiting interface before fires the call since the image size are too large.</p>