SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast sffc's Avatar
    Join Date
    Jul 2006
    0 Post(s)
    0 Thread(s)

    Showing Loading Div for SJAX Requests

    In my current project, I am using SJAX (i.e. synchronous AJAX) requests instead of pure AJAX requests in several places for better usability. One place is on the "unload" event, where the XMLHttpRequest must be synchronous in order for the program to work.

    Anyway, when there is latency on the server, especially in peak traffic hours, it can be confusing to the user to see a frozen page for a couple of seconds while the SJAX request loads. As such, it would be beneficial to have a "loading" div reveal itself while the loading is taking place.

    Here is the concept I currently have in place:
    Code JavaScript:
    document.getElementById("sjaxsubmitting").style.display = "block";
    // Start Request
"POST", "myfile.php", false);
    reqobj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    // Finish Request
    document.getElementById("sjaxsubmitting").style.display = "none";
    This works as expected in Firefox and Opera, although Opera is a little sluggish at first. However, Safari and Chrome continue to show the frozen screen without displaying the loading div, despite this code. I have not yet tested IE. Oddly enough, when I put a quick alert like "alert('hi there!');" before "Start Request" and after the display activating script, the loading div will appear in WebKit and will remain in sight for the duration of the request.

    What could I change to make WebKit display the div in the same way Firefox does?
    "I haven't failed, I just found
    100,000 ways that don't work"
    Thomas Edison

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    7 Post(s)
    1 Thread(s)
    If you set the sjaxsubmitting element to be visible (without actually doing the request) does it show up?

    It could be that the browser screen hasn't been repainted by the time it gets to doing the request. Reading about the alert() thingy, it seems that's probably the problem. Not sure how you'd tackle that though. Maybe calling the sjax request after a small timeout (say, 100ms) might help.


Posting Permissions

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