The AJAX --- jQuery ajax callback

jQuery's ajax callbacks

 

    // native operation regardless of the status of the request is the number of code will trigger a callback 
    var xhr = new new the XMLHttpRequest ()
    xhr.open('get', 'time1.php')
    xhr.send()
    xhr.onreadystatechange = function () {
      if (this.readyState !== 4) return
      console.log(this.responseText)
    }

 

 

// show loading 
    $ .ajax ({
      url: 'time.php',
      type: 'get',
      beforeSend: function (XHR) {
         // perform before sending all requested operation (Open, Send) 
        the console.log ( 'beforeSend' , XHR)
      },
      Success: function (RES) {
         // hide the loading 
        // will only perform this function the request is successful (status code 200) 
        console.log (RES)
      },
      error: function (XHR) {
         // hide loading 
        // only request is not normal (not a status code 200) will perform 
        the console.log ( 'error' , XHR)
      },
      complete: function (xhr) {
         // regardless of success or failure is done, will perform this complete function 
        console.log ( 'complete' , xhr)
      }
    })

 

Guess you like

Origin www.cnblogs.com/jane-panyiyun/p/12283629.html