Jquery ajax has been used to deal with the asynchronous problem, which is quite convenient. Recently, due to work project requirements, various States returned from the asynchronously submitted data source need to be processed, now I want to share with you how to learn, not to mention, directly go to the Code:
<SCRIPT src = 'jquery. js'> </SCRIPT> <SCRIPT> $ (function () {$ ("# Starts "). click (function () {$. ajax ({type: 'post', URL: 'ajax. test. PHP ', data: "username = 2", datatype: 'text', cache: false, beforesend: function (XMLHttpRequest) {$ ("# loading "). show () ;}, success: function (MSG) {alert (MSG) ;}, complete: function (XMLHttpRequest, textstatus) {$ ("# loading "). hide () ;}, error: function (data) {If (data. status = "404") {ale RT ('request address error! ');} Else if (data. status = "302") {alert ('webpage connection error');} else if (data. status = "timeout") {alert ("request timed out! ");} Else {alert ('request not responded! Check the network or VPN connection ') ;}}}) ;};}); </SCRIPT> <span id = "starts" style = "cursor: pointer; "> Start </span> | <span id =" loading "style =" display: none; "> loading ...... </span>