I am working on User authentication using Jquery mobile & php by referring a tutorial. But the tutorial back end is mongoDB. I want my application connected to PHP & mysql.
I have made some change to the tutorial code, i am confused with php return on error or success.
AJAX code
$.ajax({
type: 'POST',
url: BookIt.Settings.signUpUrl,
data:"submitted=" + "1" + "&mobile=" + mobileNumber + "&firstName=" + firstName + "&lastName=" + lastName + "&password=" + password,
dataType: "json",
success: function (resp) {
alert(resp);
console.log("success");
if (resp.success === true) {
$.mobile.navigate("signup-succeeded.html");
return;
}
if (resp.extras.msg) {
switch (resp.extras.msg) {
case BookIt.ApiMessages.DB_ERROR:
case BookIt.ApiMessages.COULD_NOT_CREATE_USER:
// TODO: Use a friendlier error message below.
$ctnErr.html("<p>Oops! BookIt had a problem and could not 2 register you. Please try again in a few minutes.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
break;
case BookIt.ApiMessages.MOBILENUMBER_ALREADY_EXISTS:
$ctnErr.html("<p>The mobile number that you provided is already registered.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
$txtMobileNumber.addClass(invalidInputStyle);
break;
}
}
},
error: function (e) {
console.log(e.message);
// TODO: Use a friendlier error message below.
$ctnErr.html("<p>Oops! BookIt had a problem and could not register you. Please try again in a few minutes.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
}
});
MY PHP return JSON encode output
echo json_encode("success");
API Message
var BookIt = BookIt || {};
BookIt.ApiMessages = BookIt.ApiMessages || {};
BookIt.ApiMessages.EMAIL_NOT_FOUND = 0;
BookIt.ApiMessages.INVALID_PWD = 1;
BookIt.ApiMessages.DB_ERROR = 2;
BookIt.ApiMessages.NOT_FOUND = 3;
BookIt.ApiMessages.EMAIL_ALREADY_EXISTS = 4;
BookIt.ApiMessages.COULD_NOT_CREATE_USER = 5;
BookIt.ApiMessages.PASSWORD_RESET_EXPIRED = 6;
BookIt.ApiMessages.PASSWORD_RESET_HASH_MISMATCH = 7;
BookIt.ApiMessages.PASSWORD_RESET_EMAIL_MISMATCH = 8;
BookIt.ApiMessages.COULD_NOT_RESET_PASSWORD = 9;
BookIt.ApiMessages.PASSWORD_CONFIRM_MISMATCH = 10;
BookIt.ApiMessages.MOBILENUMBER_ALREADY_EXISTS=11;
BookIt.ApiMessages.USERNAME_ALREADY_EXISTS=12;
how i can return error/success to this ajax, so it work fine