JQuery $ .post update not working in IE

I cannot get this update script to work in IE. Works great in any other browser. IE tells me that the update is complete. However, it is not. I no longer have hair to pull out .... BTW I tried $.ajax and $.get too .. no luck. I think this may have something to do with the live click handler. I don’t know ... I tried everything ... (I put headers for the cache, adding a random number to the end of the url line) .. nothing Frank works ... IE exploded.

This is the function $('.save').live('click') that I use:

 $(".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 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!"} 
+4
source share
9 answers

I agree with the answer above. I saw IE flake with AJAX requests, both GET and POST, when a line with a cache error is not used. Just add a random cache brute force chain to your URL as follows:

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

and it should just start working in IE.

+10
source

Finally! I solved my problem, which is related to "the same origin policy" and just raise IE !: I just changed the URL parameter: 'http://mysite.com/api/' to '/ api /' and it works !!!

Hope this helps some of you!

+2
source

You tried to remove "return false". This seems to cancel the onclick event in IE.

0
source

The first things that come to my mind is the caching issue in the AJAX request. Try adding a random value (using Math.Random () or whatever you want) to the POST request and see what happens. I always add a random value to the GET requests to ensure that the responses are unique, but I'm not sure about the POST request.

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

0
source

At this point in the process, I installed the server-side log and see what IE really publishes, and if it actually publishes anything, not many code hints, but the code looks good to me.

0
source

I recommend using link text with parameter capture enabled for debugging post mortem. It's free, so give it a try.

0
source

Have you tried using the basic .ajax method instead of the post paragraph?

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

It may not detect the data type using the post method.

Here is the 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() { } }); 
0
source

The change

 <meta http-equiv="content-type" content="text/html;charset=utf-8"> 

to

 <meta charset="utf-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> 

worked for me.

0
source

To debug such issues, make sure you get some error information. IE tends to be silent when something goes wrong, but there is a way to return an error:

 $.post("update.php",{data:"blabla"},function(){ /*... stuff to do on success...*/ },"json").fail(function(XMLHttpRequest,textStatus,errorThrown){ /*... display the errors here so you know what is wrong...*/ alert(textStatus+": "+errorThrown); }); 

At least you know what's wrong, and you can start your search more efficiently for the right solution.

0
source

All Articles