Reputation: 31
I have a simple php file that prints the date and time. I would like to load this file with jQuery so it shows the $date variable. Can't seem see why this is not working, any advice on why?
My php file:
<?php
date_default_timezone_set('GMT');
$date = date('d/m/Y H:i:s');
print $date;?>
My on page code:
<script>$(document).load(function(){
$('#time').load('http://www.my-website.co.uk/my-php-file.php');});</script>
<div id="time"></div>
Upvotes: 1
Views: 3852
Reputation: 31
code now working thanks for all the help:
<script>
$(document).ready(function(){
$('#time').load('http://www.my-website.co.uk/my-php-file.php');
});</script>
<div id="time"></div>
Upvotes: 0
Reputation: 67768
I would remove the print...
line from the php file, include the php file in your HTML page and add an echo for the $date
variable after the include line (i.e. no jquery at all):
<div id="time">
<?php
include "http://www.my-website.co.uk/my-php-file.php";
echo $date;
?>
</div>
Upvotes: 1