Let's look at an example of submitting an Ajax query using jquery.
Basic Function: enter a form, admission ticket and verification code, verify whether the form is entered, click query and submit, and then obtain and display the returned data from the server.
The Code is as follows:
Jquery section:
<Script language = "JavaScript" type = "text/JavaScript"> $ (document ). ready (function () {$ ("# btnsubmit "). click (function () {login () ;}); function login () {If (check () {loginsuccess () ;}} Function check () {if ($ ("# ksbh "). val () = "") {alert ("Admission Ticket No. cannot be blank! "); $ (" # Ksbh "). Focus (); Return false;} if ($ (" # YZM "). Val ()! = $. Cookie ('validatecode') {alert ("Verification code error! ") $ (" # YZM "). focus (); Return false;} return true;} function loginsuccess () {$. ajax ({type: "Post", URL: "/ZK/zkcj201204a", data: {ksbh: $ ("# ksbh "). val ()}, beforesend: function () {$ ("# MSG" ).html ("loading ...... submitting... please wait. ") ;}, Success: function (data) {$ (" # MSG ").html (data ). show (); document. getelementbyid ("valicode "). src = document. getelementbyid ("valicode "). SRC + '? ';}}) ;}</SCRIPT>
Htm part:
<Div id = "lmain"> <div> <SPAN class = "S1"> Admission Ticket No: </span> <SPAN class = "S2"> <input id = "ksbh" maxlength = "12" name = "ksbh" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ \ D]/g, '')" onkeyup = "value = value. replace (/[^ \ D]/g ,'') "type =" text "value =" "/> </span> </div> <SPAN class =" S1 "> Verification Code: </span> <SPAN class = "S3"> <input id = "YZM" name = "YZM" type = "text" value = ""/> </span> </div> <Div style =" text-align: center; "> <input type =" button "id =" btnsubmit "value =" query "/> </div> <Div id =" MSG "style =" Width: 600px; text-align: center; margin-top: 20px; "> </div>
Original article: http://tanteng.sinaapp.com/2012/05/jquery-ajax/