Wednesday, 21 August 2013

Whats wrong with my AJAX PHP request?

Whats wrong with my AJAX PHP request?

I'm trying to pass 3 variables to another script in my scripts folder to
query the db.
function resetPassword() {
var user = document.getElementById('username').value;
var password = document.getElementById('password').value;
var conf = document.getElementById('confirm').value;
var code = document.getElementById('code').value;
if(code.length == 0 || password.length == 0 || user.length == 0 ||
conf.length == 0) {
alert("Entries empty");
} else if(password != conf) {
alert("Passwords don't match");
} else {
$.ajax({
type: "POST",
url: "scripts/changepassword.php",
data: {Username: user, Password: password, Code: code},
dataType: "json",
success: function(data) {
alert("success");
}
});
<form>
<input id="username" placeholder="Username" name="username" type="text" />
<input id="password" placeholder="Password" name="password"
type="password" />
<input id="confirm" placeholder="Confirm Password" name="confirm"
type="password" />
<input id="code" placeholder="Code" name="code" type="text" />
<div class="registrationFormAlert" id="incorrectEntry"></div>
<p>&nbsp;</p>
<input class="btn" id="signinbut" onclick="resetPassword()" value="Reset"
type="submit" style="width:28%;" />
</form></div>
In my scripts/changepassword.php
if (isset($_POST['Username']) && isset($_POST['Password'])&&
isset($_POST['Code'])) {
}
it just refreshes the current page doesn't process the request.

No comments:

Post a Comment