SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: jQuery $.get()

  1. #1
    SitePoint Addict
    Join Date
    Apr 2005
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery $.get()

    I run the following after each file is uploaded on a multi-file upload script. It works fine for all of the files minus the last. I am using jQuery 1.7.1.

    Code:
    $.get("save.php", { rand: rand, user:"<?php echo $userid; ?>", title: title});
    If there are three files, it will run properly only the first two times. In FireBug, all the variables are fine, and it shows that it ran all three times, however the last time it ran it never actually loaded. In the 'Timeline' in Firebug it shows the spinning loading icon for the last process of save.php, along with no Status, or Size (this is in the Net tab). If I take this same URL and run it myself through my browser, it runs fine and loads instantly.

    I have been stuck on this for nearly 3 hours and I hope someone here can help.

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Could you please post the code that uploads the files as well as it's hard to determine the issue without it and a link to a working version of the code.

  3. #3
    SitePoint Addict
    Join Date
    Apr 2005
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just tested this in Chrome and it ran fine, however Firefox is still not running the last instance properly.

    To test, create a couple empty text documents and rename them to test1.mp4 and test2.mp4.
    http://tinyurl.com/c39gddm

  4. #4
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The reason why its not working is because the request is been ended before it can complete, indeed the AJAX request is been sent but because your not using an asynchronous request your if statement directly after is forcing the connection to close. A better method to use would be $.ajax() which allows you to determine whether you need an asynchronous request or not.

  5. #5
    SitePoint Addict
    Join Date
    Apr 2005
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome. I am now using $.ajax() with "async: false" and it works like a charm.

    Thanks!


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
  •