jquery ajax在mozilla工作,但不是IE

Pat*_*her 3 .net ajax jquery

我知道IE中的jquery/ajax是一个常见问题.关于堆栈溢出,这里有很多很棒的建议,但它们对我来说都没有用.下面的代码在firefox中运行得很好,但在IE中却没有:

$.ajaxSetup({ cache: false })
$.ajax({
 url: 'FunDataService.asmx/' + funDataMethod,
 type: 'POST', dataType: 'html', cache: false, timeout: 3000,
 error: function() {alert('Error updating fun information.  Refresh the page and try again.');},
 success: function(htmlFunInfo) {
  alert($(htmlFunInfo).text());
  $("#fundiv").html($(htmlFunInfo).text())},
 data: parameters
});
Run Code Online (Sandbox Code Playgroud)

你可以看到我的反缓存尝试 ; 我还在URL中添加了随机值.我也尝试在Web服务上添加各种内容标题:

'        Context.Response.ContentType = "text/html; charset=utf-8"
'        Context.Response.ContentType = "text/html"
Context.Response.ContentType = "text/plain"
Run Code Online (Sandbox Code Playgroud)

alert命令当然是用于调试的.在FF中,$(htmlFunInfo).text()是从我希望插入的服务器发送的div标签.在IE中,它是空字符串.

有谁知道如何在IE中访问此字符串值?谢谢!

编辑 服务器的响应如下:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="tempuri.org/">
  <div>stuff</div>
  <div>more stuff</div>
</string>
Run Code Online (Sandbox Code Playgroud)

我越来越认为这是错的,我需要避免绕过div.

编辑2 就是这样!在我的服务器代码中,我替换了:

Return RemarkHtml
Run Code Online (Sandbox Code Playgroud)

Context.Response.Write(RemarkHtml)
Run Code Online (Sandbox Code Playgroud)

这避免了div周围的标签,现在我很好.尽管如此,我认为这是一个很大的问题,在IE中,你无法使用.text()获取标签的内容.

多谢你们!

Jas*_*att 5

代替

alert($(htmlFunInfo).text());
$("#fundiv").html($(htmlFunInfo).text());  
Run Code Online (Sandbox Code Playgroud)

尝试

alert(htmlFunInfo);
$("#fundiv").html(htmlFunInfo); 
Run Code Online (Sandbox Code Playgroud)

问题是调用.text().html()获取所选节点的文本和HTML 内容.看起来你想要做的就是将整个响应注入其中#fundiv.