Page 2 of 2
Re: DIV refresh
Posted: Fri Jul 08, 2011 8:49 pm
by jacek
Unless you ask a specific question instead of just saying "how can I make this work ?" there is no way I can help.
Re: DIV refresh
Posted: Sat Jul 09, 2011 12:15 pm
by ashwood
well i mean.. how do i go about showing the data and auto refresh for the check every x seconds via ajax or javascript? is that better :\
Re: DIV refresh
Posted: Sat Jul 09, 2011 2:36 pm
by jacek
you can use setInterval
setInterval(function () {
alert('this will be shown every second.');
}, 1000);
Re: DIV refresh
Posted: Sat Jul 09, 2011 7:39 pm
by ashwood
yeah but i want it to show the content of the php file.. so could i use $('div').show();
and how do i load the php file ...
Re: DIV refresh
Posted: Sat Jul 09, 2011 8:23 pm
by jacek
This goes back to my original point that you should use AJAX to transfer the data only not "show a php file" or "refresh a div"
Re: DIV refresh
Posted: Sat Jul 16, 2011 2:25 pm
by ashwood
okay so where do i go from here considering i know nothing about AJAX
Re: DIV refresh
Posted: Sat Jul 16, 2011 6:26 pm
by jacek
ashwood wrote:okay so where do i go from here considering i know nothing about AJAX
Have a go at transferring an array from a php script to JavaScript via AJAX. TIP:
http://php.net/json_encode
Re: DIV refresh
Posted: Tue Jul 19, 2011 12:28 am
by ashwood
i am having a hard time understanding that json thing.. im going to forget the shoutbox for now im going to start a freeware of my Music Board.. then work on a paid for version.. so yeah for now im okay with this :/
Re: DIV refresh
Posted: Tue Jul 19, 2011 2:33 pm
by jacek
Okay. To explain json a bit anyway. It is a really easy way of transferring an array from a php script to javascript.
if In php you do
$things = array(
'first_thing' => 124,
'other_thing' => 12
);
echo json_encode($things);
You will see a slightly weird looking string, this is actually javascript code, it defines an object (you dont have to worry too much abotu this).
but now if you make an ajax request for this page from JavaScript you can just eval() the response to get the data out.
ajax.get('the_above_file.php', function (resp) {
var things = eval(resp);
});
Which then gives you an object that has the properties matching the array keys, ie
ajax.get('the_above_file.php', function (resp) {
var things = eval(resp);
alert(things.first_thing);
alert(things.other_thing);
});
would alert "124" and then "12".