HTML file:
<form action= "/index.php/welcome/personpost" >
................
<input type= "Submit" id= "Personsub" value= "submitted"/>
</form>
JS file:
$ (document). Ready (function () {
$ ("#personsub"). Live (' click ', Function ()
{
if ($ ("#oldpassword"). val () = "")
{
Alert ("Old password cannot be empty.) ");
return false;
}
var ajaxres=0;
var oldpsw=$ ("#oldpassword"). Val ();
$.ajax (
{
Type: "Post",
URL: "/INDEX.PHP/WELCOME/CHECKPSW",//To determine if the password is correct
data:{"OLDPSW": OLDPSW},
DataType: "Text",
Async:false,//Note that the default is asynchronous, false is synchronous, always wait for success to complete, and then execute the AJAX command (if (ajaxres==-1) {return FAL Se }。 Otherwise the ajaxres variable cannot be assigned correctly.
Success:function (Result)
{
if (result== "-1")//password 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 form not committed, maintained on this page
}
If ajaxres!=-1, the form commits the
});
});