JQuery Ajax Submit Form query get data instance code _jquery

Source: Internet
Author: User
Tags ticket
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>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.