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

问题描述:使用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();
        }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值