hey there i have this script´s:
$.ajax({
url: "checkAvailability.php",
type: 'POST',
dataType: "json",
data: 'username=' + $(this).data('id'),
success: function(data) {
if (result == 1) {
$("#select-err").text(data.error ? data.error : "");
}
else {
$("#select-err").text(data.error ? data.error : "");
}
}
});
in checkAvailability.php:
$availabilityChecker = new AvailabilityChecker($config);
if($availabilityChecker->check_availability($_POST['username'])) {
echo json_encode(array("error" => "is ok"));
$result = 1;
} else {
echo json_encode(array("error" => "Wrong chose"));
$result = 0;
}
while testing i found out that this is not the correct way to check if a php-clause is true or false, so i need your help...could anyone show me how to check this via jquery? greetings and thanks!
UPDATE: i changed to:
$availabilityChecker = new AvailabilityChecker($config);
if($availabilityChecker->check_availability($_POST['username'])) {
echo 1;
} else {
echo 0;
}
and:
$.ajax({
url: "checkAvailability.php",
type: 'POST',
dataType: "json",
data: 'username=' + $(this).data('id'),
success: function(data){
if(data == 1){
$("#select-err").text(data.error ? data.error : "is ok");
}
else{
$("#select-err").text(data.error ? data.error : "not ok");
}
}
});
it works, BUT: if data == 1, on my page "1" is displayed, why and how can i fix this?
AvailabilityChecker, we have no idea what that looks like and can't help you with that.echo json_encode(array("error" => "is ok", "result" => 1));, and then in the ajax call check it withif (data.result == 1) {...