Reputation: 76
I sent an ajax request and it either returns the word "false" or "Username". I got this to work fine. On success it puts the word "false" or the "Username" into the .body class div. The problem I am having is that I want to check if "false", or not "false" exists. So that my password field can disable or undisable. The thing is everything works fine and is tested. My issue is that when I check the "false" it thinks that it exists as NULL. Whatever the ajax sends out it is a foreign data type, although it can display it in html, I can seem to then store it in a variable and check if "false" exists.
$(function () {
$(".Guide_Welcome_Container").hide();
$("#inputPassword").attr("disabled", "disabled");
$("button").click(function () {
$(".Guide_Welcome_Container").fadeToggle(1000);
$(".HeaderLogin").fadeToggle(1000);
});
$("#inputEmail").keyup(function () {
var UsernameInput = $(this).val();
$.ajax({
type: "POST",
url: "PullUserDb.php",
data: {
'UsernameInput': UsernameInput
},
dataType: "html",
success: function (data) {
$('#BodyID').html(data);
var GoodUsername = $("#BodyID").html();
if (GoodUsername != "false") {
$("#inputPassword").attr("disabled", "disabled");
} else {
$("#inputPassword").removeAttr("disabled");
}
//
}
});
});
});
Upvotes: 0
Views: 2685
Reputation:
$("#BodyID").html() //might contain some html too
Try
console.log($("#BodyID").html());
within your success callback to see what it returns
Upvotes: 0
Reputation: 26
Put this in your success function (I'm assuming you're being returned the string 'false'
, not a boolean, but if I'm wrong, swap out 'false'
for false
):
if (data !== 'false') {
// 1. put username on the page, like you do in the above code
// 2. enable password field
} else {
// disable password field
}
No need to put it on the page, then check what you put on the page. You're already being returned the username in the data
object.
Upvotes: 0
Reputation: 342
in your code
dataType: "html"
try json instead of html :) i user this struct
{success:true,message:'OK'}
Upvotes: 1