#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    4
    Rep Power
    0

    Question Need help in update values without refreshing


    Hi guys. I'm having a prob here and would like some help . The basic idea is I am making a web based game, an interactive one. The game is able to create different rooms for 1 vs 1 battle.

    For every room created, a php file named as the room name is created which keeps a temp record of the players status example ($HP = 200 and things like that. This php file updates in real time during gameplay. I include this php into the players page so it can display the status, but however I can't auto update it real time without refresh.

    So is there anyway I can re-include the php file every x seconds so that the old values can are updated with new ones? Or anyway I can keep retrieving the new update values from the php file to work with? Thanks in advance .
  2. #2
  3. (retired)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2003
    Location
    The Laboratory
    Posts
    10,101
    Rep Power
    0
    You want "AJAX", where the J is for Javascript.


    --Simon
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    4
    Rep Power
    0
    I've read up on AJAX and some AJAX examples on the net. But most examples on the net only show results in text without refresh. So if AJAX is the best solution to it, can anyone show me the way to update the values using AJAX every x seconds ? Sorry but I really know nuts with AJAX or you can also say i am very noob in writing scripts, lolz .
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    4
    Rep Power
    0
    Hey, I've found the solution to it. Thanks for the help anyway but i've another problem rising after this one that I've overlooked, damn. lolz ! I call the following functions every x seconds using a js setTimout().

    function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
    }
    but after a few tries of retrieving the file from server, the browser don't bother to fetch and it keeps retrieving the old file inside my temp internet folder which has the old data.

    Can anybody care to help me with this?
  8. #5
  9. 4:04 Time Not Found
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2004
    Location
    Northern Virginia
    Posts
    2,273
    Rep Power
    338
    Try calling include_dom() with something like this, it should trick the browser into reloading a full version of your js every time.
    Code:
    var src = 'http://whatever.com/whatver.js?'+ Math.random() +'';
    include_dom(src);
    I am so smart, I am so smart, S.M.R.T ... I mean S.M.A.R.T.

    Stop Using Pop-Ups
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    4
    Rep Power
    0
    Originally Posted by vbrtrmn
    Try calling include_dom() with something like this, it should trick the browser into reloading a full version of your js every time.
    Code:
    var src = '(URL address blocked: See forum rules)/whatver.js?'+ Math.random() +'';
    include_dom(src);

    Bingo ! Indeed a simple line can counter the "stupid" browsers prob. Oh.... I got bad headaches for days cuz of this problem . Very big thks vbrtrmn ! No more panadols for me lolz. Cheers

IMN logo majestic logo threadwatch logo seochat tools logo