SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    501
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    While loop that only works with alerts?

    i have a loop that calls an ajax function that checks to see if a file exists. it looks like this...

    Code:
    /* some functions up here */
    var exists = 0;
    while (exists != 1) {
       ajaxfunction("restoreExists", "/file/path/");
       if (output) { exists = 1; }
    }
    /* some functions down here */
    however, the above code simply locks up my browser. by the time this function is called, the file should be available within seconds.

    BUT - when i add in an alert() showing me the status of "exists" it works fine, just with an annoying alert() box.

    Code:
    /* some functions up here */
    var exists = 0;
    while (exists != 1) {
       ajaxfunction("restoreExists", "/file/path/");
       if (output) { exists = 1; }
       alert(exists);
    }
    /* some functions down here */
    any ideas on what i can do without having to call on an alert()?

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    could it be that output is never populated? and its looping forever, yet when using an alert it shows you that it is in fact working.

    Ignore that. just realised you said that with the alert it works fine.

    So have you got a debugger like FireBug or Visual Studio that you can debug the javascript on?


  3. #3
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    501
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i do have firebug, but like i said, firefox completely shuts down when i run it sans alert().

    which, to me, makes no sense. the value is obviously being passed cause when i alert(exists) i get a return and the while loop ends then proceeds down the list.

    if i don't have an alert() even present it locks up. so i dunno. i'm confused. ha.

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would it be possible to PM me the url or post the URL so we can have a look our selves?


  5. #5
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    501
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this isn't an external website or else i would.

  6. #6
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so no way to post some sample code?


  7. #7
    SitePoint Zealot the DtTvB's Avatar
    Join Date
    Jul 2006
    Location
    Thailand
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would use document.title. But not sure would it work or not.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •