What I’m trying to do is to use ajax to get time from another php file.
So the javascript code looks like this:
var timeNow = setInterval(
$.ajax({
url: "process/time.php",
success: function(msg) {
$('#time').text(msg);
}
}), 1000);
And here’s php code it is posted to.
<?php echo gmdate('h:i:s A', time() + 8 * 3600);?>
Any ideas?
setIntervalcan be called with a Function object as well as a string of code to execute.$.ajaxreturns ajqXHRobject, which is casted to the string"[object Object]". This string is then executed as code, and raises the error.You want to wrap the
$.ajaxcall in a function: