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
});
});