Hi I have searched the web but can't get this to work. I'm trying to call the file databaseUpdated.php (placed in the same folder as the index.php file) from a function that is called every 10 seconds.
If I place the following in the index.php
<script type='text/javascript'>updateboolean();</script>;
the function is runned so thats not the problem, the problem is that the php file is not read.
the file databaseUpdated.php
<body>
<?php
echo ("<script type='text/javascript'>updateboolean();</script>;");
?>
</body>
And here is my functions in the javascript
$(document).ready(function(){
setInterval(function() {
$.get("databaseUpdated.php");//Can't get this to work any obvious reason for this (And yes I have jquery working)?
return false;
}, 10000);
});
function updateboolean(){
alert("Database updated");
document.location.reload(true);
}
Thanks in advance =)
Edit
_________________________________________________________________________________________
When I do
alert(data); in the below function I get the result as the image will show
$(document).ready(function(){
setInterval(function() {
$.get('databaseUpdated.php', function(data) {
alert('Load was performed.');
alert(data);
eval(data);
});
}, 5000);
});
enter image description here
But the "eval(data)" doesn't seem to work
5 Answers 5
$.get("databaseUpdated.php"); // This will only return contents of that file The scripts in that file are not executed. To execute them you need to do eval(). So Try This
$.get('databaseUpdated.php', function(data) {
eval(data);
});
Also, may be you will require to change your php file as following:
echo ("updateboolean();");
Comments
where is your callback function for ajax this is how it should be
$(document).ready(function(){
setInterval(function() {
$.get('databaseUpdated.php', function(data) {
alert('Load was performed.');
});
}, 10000);
});
Comments
Try this:
$(document).ready(function(){
setInterval(function() {
$.get('databaseUpdated.php', function(data) {
alert("Database updated");
// or alert(data); //in case you return data from php
document.location.reload(true);
});
}, 10000);
});
Comments
By doing $.get("databaseUpdated.php"), you request the PHP page, but ignore the return results.
Try this:
PHP
echo "updateboolean();";
JavaScript:
$.getScript("databaseUpdated.php");
Comments
try this in place of your echo
echo "<script>updateboolean();</script>";
if (data.success) { callthisFunction(); }or at the very least using getScript - since that's what you're doing.