I am newbie at PHP. I wanted to build a small project of room booking, and improve it by using AJAX.
http://img851.imageshack.us/img851/6172/88303815.png
I'm trying to display an alert message every time someone is reaching the limit of two hours room time. The registration div is where all the PHP is taking care of the "Get Room" action. My problem is that the room_per_user function does not show the correct amount of rooms per user unless I refresh the page.
How can i correct my code to present the error message?
$("#formReg").ajaxForm({
url: "room.php",
type: "POST",
beforeSubmit: disableButtons,
success: function(data) {
$("#registration").load("room.php #registration", function() {
$(function() {
<?php
if(rooms_per_user($_SESSION['user_id'])>=2)
{
$string = "\$(\"#dialog-message\").find('.error').show();";
echo $string;
}
?>
$( "input:submit, a, button", ".registration" ).button();
$( "a", ".registration" ).click(function() { return false; });
});
});
$("#cancellation").load("room.php #cancellation", function() {
$(function() {
$( "input:submit, a, button", ".cancellation" ).button();
$( "a", ".cancellation" ).click(function() { return false; });
});
});
});
function disableButtons(){
$('form').find('input[type="submit"]').attr('disabled', 'disabled');
}
Thank you very much, and forgive if I did some fatal mistakes ;-)
Sorry, I copied the code wrong in the PHP part (i tried to shorten it up and forgot the PHP tag)
EDIT 2: I tried to use the json encode but i don't know why it doesn't work for me... It get stuck at the submit button disabling phase. When I delete the datatype line it works fine... Help anyone? Thank you very much for your answers!
$("#formReg").ajaxForm({
url: "room.php",
dataType: 'json',
type: "POST",
beforeSubmit: function() {
$('form').find('input[type="submit"]').attr('disabled', 'disabled');
},
success: function(data) {
alert(data.status);
$("#registration").load("room.php #registration", function() {
$( "input:submit, a, button", ".registration" ).button();
$( "a", ".registration" ).click(function() { return false; });
});
$("#cancellation").load("room.php #cancellation", function() {
$( "input:submit, a, button", ".cancellation" ).button();
$( "a", ".cancellation" ).click(function() { return false; });
});
}
});
rooms_per_userPHP function?$_SESSION['user_id']is being called as javascript. But that is PHP is an array that PHP uses. What does room.php return?