jQuery $.post update not working in IE

大城市里の小女人 提交于 2019-11-29 14:53:38
Aditya

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().getMilliseconds(), { cache : false, saveID : saveIt.value, saveMo : saveMonth, saveYr : saveYear, saveCtg : saveCt, saveThg : saveTh },
      function(data){
...

and it should just start working in IE.

Finally! I solved my problem which is because of "same origin policy" and just raise in IE!: I've just change the URL parameter from : 'http://mysite.com/api/' to '/api/' and it works!!!

hope it help some of you!

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

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

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.

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

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() {

    }
});  

Changing

<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.

For debugging problems like these make sure you get some information about the error back. IE tends to be silent when something goes wrong, but there is a way to get an error back:

$.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 searching more effectively for the right solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!