views:

512

answers:

7

I can't get this update script to work in IE. Works fine in every other browser. IE tells me that the update was performed. However, it wasn't. I've no more hair left to pull out..grr. BTW I've tried $.ajax and $.get too..still no luck. I'm thinking it may have something to do with the live click handler. Don't know...I've tried everything..(putting headers for no-cache, attaching a random number to the end of my url string)..nothing fricken works...blasted IE.

This is the $('.save').live('click') function I am using:

$(".save").live("click", function(){
  $.post("update.php", { cache : false, saveID : saveIt.value, saveMo : saveMonth, saveYr : saveYear, saveCtg : saveCt, saveThg : saveTh },
  function(data){
    if(data.success) {

      $(textareaThoughts).hide();
      $(saveIt).parents(".dirRowOne").find(".cancel").hide();
      $(saveIt).parents(".dirRowOne").find(".edit, .del").show();
      $(saveIt).hide();
      $("#dirConsole").html(data.message);

    } else if(data.error) {
    }
  }, "json");
return false;
});

Here's the update.php

<?php

  if($_POST) {

      $data['id'] = $db->escape_value($_POST['saveID']);
      $data['months'] = trim($db->escape_value($_POST['saveMo']));
      $data['years'] = trim($db->escape_value($_POST['saveYr']));
      $data['cottages'] = trim($db->escape_value($_POST['saveCtg']));
      $data['thoughts'] = trim(htmlentities($db->escape_value($_POST['saveThg'])));

      $id = $data['id'];
      $m = $data['months'];
      $y = $data['years'];
      $c = $data['cottages'];
      $t = $data['thoughts'];

      $query = "UPDATE //tablename SET month = '{$m}', year = '{$y}', cottage = '{$c}', thoughts = '{$t}'  WHERE dirID = '{$id}'";
      $result = $db->query($query);

       if($result) {
          $data['success'] = true;
          $data['message'] = "Update Successful!";
       } else {
          $data['error'] = true;
       }

 echo json_encode($data);

 }


?>

This is the JSON response:

{"id":"360","months":"June","years":"1990","cottages":"Cedar","thoughts":"Hello","success":true,"message":"Update Successful!"}
A: 

Have you tried removing the "return false". This seems to cancel the onclick event in IE.

devpl
Haven't tried that..I'll give it a shot.
Scott
Nope..still no workie.
Scott
I see. When you said that IE tells you that it performed the update, does it mean that IE executed the lines within the data.success block? And that the problem is that the data that should have been updated wasn't updated in your DB? If so, maybe there's a problem with how IE parses what you send to the POST parameters? That is, maybe you can try alerting the following: { cache : false, saveID : saveIt.value, saveMo : saveMonth, saveYr : saveYear, saveCtg : saveCt, saveThg : saveTh }Maybe saveMonth should be saveMonth.value (just like saveIt.value)?
devpl
Yep...it's makes it through the `data.success` block, and says the update was successful. The var that I used for saveMonth is the value. Weird stuff...some kind of caching problem me thinks.
Scott
A: 

First things that comes to my mind is a caching problem on the AJAX request. Try appending a random value (using Math.Random() or whatever you want) to the POST request and see what happens. I always append a random value to GET requests to ensure the responses are unique but I'm not sure how about the POST request.

Also check out this link and see if any of it applies: http://greenash.net.au/posts/thoughts/an-ie-ajax-gotcha-page-caching

NinjaBomb
I have tried all of these suggestions...nothing works. Thanks for the info tho.
Scott
`POST` is normally not to be cached. Also IE knows that.
BalusC
A: 

At this point in the process I would set up a server side log and see what IE is actually posting and if it was actually posting anything, not much of a code hint but the code looks good to me.

Kristoffer S Hansen
+1  A: 

I agree with the answer above. I've seen IE flake with AJAX requests, both GET and POST, when a cache-busting string is not used. Just append a random cache busting string to your URL like so:

    $.post("update.php?ts="+new Date().milliSeconds(), { cache : false, saveID : saveIt.value, saveMo : saveMonth, saveYr : saveYear, saveCtg : saveCt, saveThg : saveTh },
      function(data){
...

and it should just start working in IE.

Aditya
A: 

Hello,

I recommend using link text with turned on parameter value capturing for post mortem debugging. It is free so give it a try.

Alois Reitbauer
A: 

This question is a bit old, and I don't have a silver bullet either, but:

Did you know that Internet Explorer 8 has a fairly decent Javascript debugger built-in? It is almost as good as Firebug. Try it out and single-step your problem. Then try again with Internet Explorer 7.

I think IE8 is finally a browser which is okay to work with. It also has an IE7 compatibility mode.

And you know, the previous tips with cache-busting are important. I already solved IE problems with cache-busting. Perhaps in your despair you implemented cache-busting not quite correctly. I know, this happens to me too, if nothing works, it is very very frustrating.

Good luck!

nalply
A: 

Have you tried using the base .ajax method instead of the post abstraction?

http://docs.jquery.com/Ajax/jQuery.ajax#options

Perhaps it's not detecting the datatype with the post method.

Here is an full ajax call that works for me:

$.ajax({
    type: "POST",
    url: "content_admin.asmx/UpdateFolderDocumentOwner",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: '{documentID:' + $("#did").val() + '}',
    error: handleJsonError,
    success: function() {

    }
});
ScottE