DIV refresh

JavaScript related questions should go here.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: DIV refresh

Post 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.
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: DIV refresh

Post 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 :\
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: DIV refresh

Post by jacek »

you can use setInterval
setInterval(function () {
    alert('this will be shown every second.');
}, 1000);
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: DIV refresh

Post 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 ...
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: DIV refresh

Post 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"
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: DIV refresh

Post by ashwood »

okay so where do i go from here considering i know nothing about AJAX
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: DIV refresh

Post 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
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: DIV refresh

Post 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 :/ :)
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: DIV refresh

Post 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".
Image
Post Reply