jquery Ajax places to note in the click handling of the Submit button

Source: Internet
Author: User

HTML file:

<form action= "/index.php/welcome/personpost" >

................

<input type= "Submit" id= "Personsub" value= "Submit"/>

</form>


JS file:

$ (document). Ready (function ()

{
$ ("#personsub"). Live (' click ', Function ()
{
if ($ ("#oldpassword"). val () = = "")
{
Alert ("The old password cannot be empty!") ");
return false;
}
var ajaxres=0;
var oldpsw=$ ("#oldpassword"). Val ();
$.ajax (
{
Type: "Post",
URL: "/INDEX.PHP/WELCOME/CHECKPSW",//determine if the password is correct
data:{"OLDPSW": OLDPSW},
DataType: "Text",
Async:false,Note that the default is async, false is synchronous, always waits for success to finish, and then executes the AJAX command (if (ajaxres==-1) {return false;}. Otherwise the ajaxres variable cannot be assigned correctly.
Success:function (Result)
{

if (result== "-1")//password is incorrect
{

Ajaxres=-1;
Alert ("Old password input error, please re-enter!") ");
$ ("#oldpassword"). Val ("");
$ ("#oldpassword"). focus ();
return false//here, return false is useless
}
}
});

if (ajaxres==-1)
{
return false; return false here to make the form not committed, maintained on this page
}
If ajaxres!=-1, the form submits a


});
});

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.