Look at an example of an AJAX query that submits a form with jquery.
Basic function: The user enters a form, enters the admission ticket and the verification code, verifies whether the user enters the form, clicks the query to submit, then obtains the return data from the server and displays.
The code is as follows:
jquery section:
Copy Code code as follows:
<script language= "javascript" type= "Text/javascript" >
$ (document). Ready (function () {
$ ("#btnSubmit"). Click (function () {
Login ();
});
});
function Login () {
if (Check ()) {
Loginsuccess ();
}
}
function Check () {
if ($ ("#ksbh"). val () = "") {
Alert ("Ticket number cannot be empty!") ");
$ ("#ksbh"). focus ();
return false;
}
if ($ ("#Yzm"). Val ()!= $.cookie (' Validatecode ') {
Alert ("Authentication 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 ... Please wait while the submission is in progress. "); },
Success:function (data) {
$ ("#msg"). HTML (data). Show ();
document.getElementById ("Valicode"). src = document.getElementById ("Valicode"). src+ '? ';
}
});
}
</script>
HTM section:
Copy Code code as follows:
<div id= "Lmain" >
<div><span class= "S1" > Ticket Number: </ Span><span class= "S2" ><input id= "KSBH" maxlength= "name=" KSBH "onbeforepaste=" ClipboardData.setData ( ' Text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, "") "onkeyup=" Value=value.replace (/[^\d]/g, "") "type=" Text "value=" "/></span></div>
<div><span class=" S1 "> Authenticode: </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>
<div id= "msg" style= " Width:600px;text-align:center; margin-top:20px; " ></div>