ajax works and then dies...

Discussion in 'JavaScript' started by jkashu, Oct 18, 2008.

  1. #1
    My ajax page displays information from a database. It basically goes to the database every second by running a php script that return xml. Javascript parses the xml and puts it into div tags.

    My page works perfectly for a while, but if I leave the page up for a few hours it will stop working and new data will not display?

    What could be causing this?? Thanks!
     
    jkashu, Oct 18, 2008 IP
  2. Xexi

    Xexi Well-Known Member

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    100
    #2
    Can you post the source?
     
    Xexi, Oct 19, 2008 IP
  3. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If it works for five minutes, there's no reason it will stop after say 2 hours.. Maybe your DB crashes, your web server crashes or something similar is happening, which is not affected by the script. You can start by checking this things.
     
    xlcho, Oct 19, 2008 IP
  4. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #4
    er, if it does go and do an ajax call every 1 second, how do you chain this? setTimeout(functionName, 1000) with a self-referencing call within functionName?

    consider this: usually, your ajax script, if done well and via GET and not POST, will have a reply within 150-200ms tops - use firebug to look at it and confirm your average response times. however, this does not matter - all it takes is for 1 of these to timeout a little - say, due to network lag, cpu strain or whatever - and for the response time to go over 1000ms, running into the next cycle...

    i think your fix ought to be something along the lines of:
    create onSuccess event on the ajax handler and do the recursive call to self within it. you can also add some timers that calculate before and after time on the XHR and then determine the difference beween 1000ms and that, using it for the setTimeout within the onSuccess. I hope this makes sense... Also - make sure you dysable async. good luck
     
    dimitar christoff, Oct 20, 2008 IP