您的位置:首页 > 理论基础 > 计算机网络

使用jquery中的ajax进行post请求时,报错,提示[object XMLHttpRequest]

2013-07-03 16:22 826 查看
问题描述:使用jquery进行ajax post请求时,报错,提示[object XMLHttpRequest],在谷歌浏览器中发现此问题,IE7/8/9/10都没问题

现象1:



现象2:

同时在事件查看器中也相应发现如下事件内容:

Event code: 3005
Event message: 发生了未处理的异常。
Event time: 2013/7/3 15:53:23
Event time (UTC): 2013/7/3 7:53:23
Event ID: b3b2dd2f8f88403f87810651cfabbfb6
Event sequence: 74
Event occurrence: 1
Event detail code: 0

Application information:
Application domain: /LM/W3SVC/2/ROOT-8-130173115807222308
Trust level: Full
Application Virtual Path: /
Application Path: D:\Project\Portal\code\MaintenanceSystem.Web\
Machine name: PC201305021047

Process information:
Process ID: 3876
Process name: w3wp.exe
Account name: PC201305021047\Administrator

Exception information:
Exception type: HttpException
Exception message: 远程主机关闭了连接。错误代码是 0x80070057。

Request information:
Request URL: http://localhost:8001/WebService/DataSync.aspx Request path: /WebService/DataSync.aspx
User host address: ::1
User:
Is authenticated: False
Authentication Type:
Thread account name: PC201305021047\Administrator

Thread information:
Thread ID: 16
Thread account name: PC201305021047\Administrator
Is impersonating: False
Stack trace:    在 System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
在 System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
在 System.Web.HttpResponse.Flush(Boolean finalFlush)
在 System.Web.UI.HtmlTextWriter.Write(String s)
在 System.Web.UI.LiteralControl.Render(HtmlTextWriter output)
在 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
在 System.Web.UI.Page.Render(HtmlTextWriter writer)
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Custom event details:


前台请代码如下:

$.ajax({
url: '/WebService/DataSync.aspx',
type: 'POST',
data: { Action: "GETCATEGORYCODE", CategoryId: cid, ParentId: pid, Order: order },
dataType: 'text',
timeout: 1000,
error: function(ex) { alert(ex); },
success: function(result) {
var r = result.split(":");
$('#<%=txtCategoryCode.ClientID %>').val(r[1]);
if (r[0] == "true") {
$('#<%=txtCategoryCode.ClientID %>').next().hide();
$('#<%=RequiredFieldValidator2.ClientID %>').show();
$('#<%=RequiredFieldValidator2.ClientID %>').html("编码已存在");
$('#<%=btnSave.ClientID %>').attr("disabled", true);
}
else {
$('#<%=txtCategoryCode.ClientID %>').next().show();
$('#<%=RequiredFieldValidator2.ClientID %>').hide();
$('#<%=btnSave.ClientID %>').attr("disabled", false);
}
}
});


后台DataSync.aspx.cs代码如下:

protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.BufferOutput = false;
Response.ContentEncoding = System.Text.Encoding.UTF8;
switch (Action)
{
case DataSyncAction.GetCategoryCode:
GetCategoryCode();
break;
default:
break;
}
Response.Flush();
Response.End();
Response.Close();
}


解决方法:

发现在以上后台代码中如果将Response.BufferOutput的值改为true现象1仍然存在,但现象2消失,如果进一步将以上代码中的Response.Flush();去掉的话则问题解决。

正确代码如下:

protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.BufferOutput = true;
Response.ContentEncoding = System.Text.Encoding.UTF8;
switch (Action)
{
case DataSyncAction.GetCategoryCode:
GetCategoryCode();
break;
default:
break;
}
//Response.Flush();去掉此句代码
Response.End();
Response.Close();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐