Below I have a Json function and some php code which it retrieves.
JavaScript code:
function postback(){
if(validation()){
$.getJSON(
{"room_no":$("#room").val()},
function(json){
$("#roomAlert").html(json.msg)
});
}
}
PHP code:
if (isset($_POST['prequestion'])) {
$roomquery = "
SELECT Room
FROM Room
WHERE
(Room = '".mysql_real_escape_string($roomChosen)."')
";
$roomnum = mysql_num_rows($roomresult = mysql_query($roomquery));
mysql_close();
if($roomnum ==0){
$msg = "This Room is Invalid";
} else {
$msg = "";
}
$d = array("msg" => $msg);
echo json_encode($d);
}
?>
What my question is that I have a myClickHandler() function and I want it to showConfirm() if the validation() is met and if the postback() function is met if in php $msg = “”; The validation is met but how can I meet the postback() requirement?
Below is the myClickHandler() function:
function myClickHandler(){
if(validation()){
showConfirm();
}
}
You need to use a callback to accomplish this:
}
If you are unfamiliar with how callbacks work in JavaScript, check out this article:
http://recurial.com/programming/understanding-callback-functions-in-javascript/