Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: AJAX Problem

  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AJAX Problem

    I'm having a weird issue using jQuery's $.ajax function. When I pass 5 pieces of data, either by GET or POST, the script runs as I would like. However, when I have any more than 5, the script does not run. Does this have something to do with the amount of data that can get passed through an AJAX request?

    Here's the relevant code...(the alerts are just to test if it's working)
    Code:
    $(".barcrawl-stop-id").each(function(){
        alert("running ajax function");
        $.ajax({
              url: "/handlers/ajax/barcrawl_reorder.php",
              cache: false,
              type: "POST",
               data: ({
                   stop: n,
                   id: $("#barcrawl-id").val(),
                   stop1: stop1,
                   stop2: stop2,
                   stop3: stop3,
                   }),
              success: function(html){
                  alert(html);
                
              }
        });
        n++;
                
    });
    When I run this, it works fine. (I get the "running ajax function" alert once for each instance of .barcrawl-stop-id there is, and then I get an alert with the returned AJAX data).

    However, when I run it with another piece of data, for example, "stop4: stop4," I only see "running ajax function" once, and the script fails. Again, what could be causing this?

    Thanks.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Two things strike me:

    1. Why are there parentheses around the data object?

    Code:
    data: ({
    	stop: n,
    	id: $("#barcrawl-id").val(),
    	stop1: stop1,
    	stop2: stop2,
    	stop3: stop3,
    }),
    You don't need those.

    2. You have a comma after the last item in the object:

    Code:
    stop3: stop3,
    Firefox doesn't seem to mind it, but IE tends to throw a hissy fit at those.


  •  

    Posting Permissions

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