2

Oh boy, yet another question about IE 7 and Ajax. I've read numerous posts about IE caching and whatnot and I still cannot get this code to work in IE 7. I've tried cache busting and disabling it with Ajax setup but on success, data is what the table looked like before adding a new row. Maybe its something really simple and I'm just overlooking it.

//Submit the addData for PHP processing, remove all the additional rows then hide the div
$('input#addSubmit').click( function() {

    $.post( 'shepherd.php?a=save_data', $('form#addForm').serialize());

    //The number of rows is abratrairy so we have to find out how many there are
    //so we can slice from mainRow to the submit button row
    //The mainRow is the 2nd index

    var addLength = $("table#addTable tr").length - 1;
    $("table#addTable tr").slice(3,addLength).remove();

    rowCount = 2;
    lastRow = $('tr#mainRow');

    //Remove values from the main row
    $(".addMainData").val("")

    //Pull an updated version of the main table then delete the current one

    $.post( 'shepherd.php?a=refresh_table&buster=' + new Date().getTime(),
            function(jquery_data) {
                //alert(jquery_data);
                $('div#mainContent').empty().html(jquery_data);
            });     

    $("div#addDiv").hide(400);
});
Barmar
  • 741,623
  • 53
  • 500
  • 612
Useless Intern
  • 1,294
  • 1
  • 10
  • 20
  • try using the full URL instead of `'shepherd.php?a=save_data'` http://stackoverflow.com/questions/2320090/jquery-ajax-method-in-ie7-ie6-not-working-but-working-fine-in-firefox – jcho360 Dec 19 '13 at 20:56
  • Why would that make a difference? I don't see the relation to the linked question, which uses `$(this).attr("href")` where the href contains a hash. – Barmar Dec 19 '13 at 20:58
  • Is your second AJAX call dependent on the results of the first one? Then you need to do it in the first one's callback function. You're not waiting for the first one to finish, so you're getting old data. – Barmar Dec 19 '13 at 21:00
  • Why not put a random number in the `$.post` request so it doesn't request the same URL (which the browser would cache...) – Nahydrin Dec 19 '13 at 21:02
  • @BrianGraham That's what his `buster=` parameter is. – Barmar Dec 19 '13 at 21:03
  • @Barmar Oh, I didn't see that, my bad. – Nahydrin Dec 19 '13 at 21:04

1 Answers1

3

You need to do the second AJAX call in the callback of the first one, so that it doesn't run before the first one updates the database.

//Submit the addData for PHP processing, remove all the additional rows then hide the div
$('input#addSubmit').click( function() {

    $.post( 'shepherd.php?a=save_data', $('form#addForm').serialize(), function() {

        //The number of rows is abratrairy so we have to find out how many there are
        //so we can slice from mainRow to the submit button row
        //The mainRow is the 2nd index

        var addLength = $("table#addTable tr").length - 1;
        $("table#addTable tr").slice(3,addLength).remove();

        rowCount = 2;
        lastRow = $('tr#mainRow');

        //Remove values from the main row
        $(".addMainData").val("")

        //Pull an updated version of the main table then delete the current one

        $.post( 'shepherd.php?a=refresh_table&buster=' + new Date().getTime(),
                function(jquery_data) {
                    //alert(jquery_data);
                    $('div#mainContent').empty().html(jquery_data);
                });     

        $("div#addDiv").hide(400);
    });
});
Barmar
  • 741,623
  • 53
  • 500
  • 612