Search code examples
jqueryasynchronousinternet-explorer-7internet-explorer-6

jQuery: 'async: false' Not Working With IE7 / IE6


I created a simple tracking script which adds the users info to a database when the page is unloaded. It works on all browsers except IE7 and IE6.

IE7 gives me errors, but I can't open the "debugger" because I'm using the standalone version (or at least that's what I think the problems is). I removed the async: false, from the script below and I didn't get any errors, but I need async set to false in order for the script to work. Any ideas?

$(window).unload(function() {
  $.ajax({
    type: "POST",
    async: false,
    url: "add.php",
    data: "ip=" + jIp + "&date=" + jDate + "&time=" + jTime,
  });
});

Solution

  • Your code has the following line:

    data: "ip=" + jIp + "&date=" + jDate + "&time=" + jTime,
    

    This code is broken in IE6/7, because there is a trailing comma in the object literal's property list. This is arguably legal Javascript, but is the source of no end of IE-specific errors. Remove the last comma and your call will work.