I am trying to run a script in the background of my PHP pages that will check if new messages have been added to the database and notify the user.
I used AJAX to call a file with the code and the setTimeout() to call it every 10 seconds.
The problem is that the ajax is not returning any data. I tried just putting "return: 1;" but i still get an blank alert box.
PHP:
require('connect.php');
require_once("inc/init.php");
$check_Mail_footer = $con->prepare("SELECT * FROM mail WHERE `to` = ? AND `deleted` = ? AND `read` = ?");
$check_Mail_footer->execute(array($user_id,0,0));
$result = $check_Mail_footer->fetch(PDO::FETCH_OBJ);
return array($result->from, $result->message_id);
Javascript:
function checkNewMail(){
$.ajax({
url: 'newMessageCheck.php',
success: function(info)
{
alert(info);
}, error: function()
{
alert('something went wrong');
}
});
}
setTimeout( checkNewMail() ,10000);