I want to validate a password via JavaScript with help of an Ajax function.
If it is successful, I want to pass back the variable (boolean, true or false) and do something in my PHP file depending on the callback.
But this doesn't work. Here is my code:
PHP file: update.php
<input href="javascript:void(0);" role="button" ype="submit" value="Submit" onclick="ValidatePassword()>'
JAVASCRIPT: ValidatePassword()
In my Javascript function I check the password with this ajax call and if it is successfull, it should callback the result to the php function.
$.ajax({
type: "POST",
url: "checkpw.php",
data: dataString,
cache: false,
success: function(response)
{
if (result != -1 )
{
$("#passwd").val('');
// RETURN TO PHP FILE update.php -> PW IS VALID
} else {
// RETURN TO PHP FILE update.php -> PW IS INVALID
}
}
});
PHP file: update.php
Now I want to use the callback in the php function like:
<?php
if (passwordCallback == true)
...
else
...
?>
What should I do in the ajax success function to return the value to my php file?
success: functionisresponsewhile in your condition you're usingresult.update.phpand pretend the password is valid if you go via JavaScript. You should instead callupdate.phpviacheckpw.phpand send the response directly from that.