2011-12-14 67 views
0

我經常使用jQuery來調用我的頁面方法,它工作正常。所以現在我正在嘗試從page1.aspx到page2.aspx的調用頁面方法。我在page1.aspx中,並試圖調用page2.aspx中的頁面方法,這裏出現錯誤。jquery ajax和服務器端方法調用錯誤asp.net

這樣我打電話頁method-- jQuery代碼,這是jQuery的手短

function AjaxCallBack(MethodName, ObjParams, isAsync, OnSuccessHandler, OnErrorHandler) { 
    try { 
     //Set the callback methods for success and error 
     if (OnSuccessHandler == undefined || typeof (OnSuccessHandler) == "undefined") { 
      OnSuccessHandler = WebMethod_OnSuccess 
     } 

     if (OnErrorHandler == undefined || typeof (OnErrorHandler) == "undefined") { 
      OnErrorHandler = WebMethod_OnError 
     } 
     //Serialize the webmethod function parameters 
     var serializedParams = ""; 
     //using Json2.js; 
     serializedParams = JSON.stringify(ObjParams); 
     alert(MethodName); 
     //Make the ajax calls 
     return $.ajax({ 
      type: "POST", 
      async: isAsync, 
      url: MethodName, 
      data: serializedParams, 
      dataType: "json", 
      contentType: "application/json; charset=utf-8", 
      success: OnSuccessHandler, 
      error: OnErrorHandler 
     }); 
    } 
    catch (e) { 
     alert(e.Message); 
    } 

    return; 
} 

AjaxCallBack(SetSessionUrl, SessionParam, false, UpdateSession, SessionUpdateError); 

調用像上面。

所以請指導我什麼我需要改變我的代碼,因爲我可以從page1.aspx文件調用page2.aspx方法。請用代碼幫助我。謝謝

+0

什麼是錯誤訊息,你沒有提到? – reporter 2011-12-14 09:10:28

+0

什麼包含`MethodName`?通常你只需要調用`page2.aspx/`。 – 2011-12-14 09:14:59

回答

0

很難猜測你如何使用上面的代碼,因爲你沒有顯示任何具體的例子。但是你是否也提供了Page2.aspx的路徑,而不是它的方法名?

AjaxCallBack("page2.aspx/someWebMethod", ...) 
相關問題