jQuery $ .post更新无法在IE中运行

我不能让这个更新脚本在IE中工作。 在其他浏览器中都可以正常工作 IE告诉我更新已执行。 但事实并非如此。 我没有更多的头发可以拔出来了。 顺便说一下,我已经尝试过$.ajax$.get ..但是没有运气。 我认为它可能与live点击处理程序有关。 不知道……我已经尝试了所有的东西..(把标题放入无缓存,将随机数附加到我的url字符串的末尾)..没有fricken工作……爆炸IE。

这是我使用的$('.save').live('click')函数:

 $(".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; }); 

这是update.php

 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); } ?> 

这是JSON响应:

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

我同意上面的答案。 当没有使用缓存破坏字符串时,我看到IE浏览器带有AJAX请求,包括GET和POST。 只需将随机缓存清除字符串附加到您的url,如下所示:

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

它应该开始在IE中工作。

最后! 我解决了我的问题,这是因为“同源策略”而只是在IE中加注!:我只是将URL参数从‘http://mysite.com/api/’更改为‘/ api /’并且它作品!!!

希望对你们有些帮助!

您是否尝试删除“return false”。 这似乎取消了IE中的onclick事件。

我想到的第一件事是AJAX请求的缓存问题。 尝试在POST请求中附加一个随机值(使用Math.Random()或任何你想要的东西),看看会发生什么。 我总是在GET请求中附加一个随机值,以确保响应是唯一的,但我不确定POST请求如何。

另请查看此链接,看看是否有任何适用: http : //greenash.net.au/posts/thoughts/an-ie-ajax-gotcha-page-caching

在这个过程中,我会设置一个服务器端日志,看看IE实际上发布了什么,如果它实际上发布了什么,没有太多的代码提示,但代码对我来说很好。

我建议使用带有开启参数值捕获的链接文本进行事后调试。 它是免费的,所以试一试。

您是否尝试过使用基本.ajax方法而不是后期抽象?

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

也许它没有使用post方法检测数据类型。

这是一个适合我的完整ajax调用:

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

更改

  

  

为我工作。

对于这些调试问题,请确保获得有关错误的一些信息。 当出现问题时,IE往往会保持沉默,但有一种方法可以回复错误:

 $.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); }); 

至少你知道什么是错的,你可以开始更有效地寻找合适的解决方案。