$ .ajax - 在发送http标头后无法重定向

时间:2013-01-07 02:43:49

标签: javascript asp.net ajax

我在随机时间遇到上述错误,我无法找到解决方案。

       //MyPage.aspx
       //Reload Ajax function
       $.fn.dataTableExt.oApi.fnReloadAjax = function (oSettings, sNewSource, fnCallback) {
           if (typeof sNewSource != 'undefined') {
               oSettings.sAjaxSource = sNewSource;
           }
           this.oApi._fnProcessingDisplay(oSettings, true);
           var that = this;

           oSettings.fnServerData(oSettings.sAjaxSource, null, function(json) {
               /* Clear the old information from the table */
               that.oApi._fnClearTable(oSettings);

               /* Got the data - add it to the table */
               for (var i = 0; i < json.aaData.length; i++) {
                   that.oApi._fnAddData(oSettings, json.aaData[i]);
               }

               oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
               that.fnDraw(that);
               that.oApi._fnProcessingDisplay(oSettings, false);

               /* Callback user function - for event handlers etc */
               if (typeof fnCallback == 'function') {
                   fnCallback(oSettings);
               }
           });
       };



//Timer
function AutoReload(){
 CheckInfoDate();
 setTimeout(function(){AutoReload();}, 50000);
}

function CheckInfoDate(){
   $.ajax({
               type: "POST",
               url: "MyPage.aspx/CheckDate",
               contentType: "application/json; chartset=utf-8",
               dataType: "json",
               success: function (data) { ProcessResult(data.d); },
               error: function (orjRequest){ ErrorHandler(); }
         });
       }

      function ErrorHandler() {
           window.location.href = "../Login.aspx";
       }

       function ProcessResult(result) {
           if (result != "False") {
               RefreshDataTable();
           }
       }

      function RefreshDataTable() {
               table1.fnReloadAjax();
       }

//MyPage.aspx.cs
[WebMethod(Description="Read Date from Database")]
public static String CheckDate()
{
  //Basic SQL read from database and return as string
  return DBCustomClass.CheckInfoDate().ToString();
}

我收到的错误日志是:

  

来源:   http:// localhost:8080 / MyPage.aspx / CheckDate   System.Web.HttpException:HTTP标头出现后无法重定向   发送。
  在System.Web.HttpResponse.Redirect(String url,Boolean   endResponse)
  在System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()   在System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,   布尔和放大器; completedSynchronously)

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

虽然复发很少见,但其他时间一致(但不可复制)。我会将此问题标记为已解决。