2012-12-13 42 views
2

我試圖讓這個asp.net函數的值:jQuery的PageMethod的稱法不存在

[ScriptMethod, WebMethod] 
public static bool checkRefresh() 
{ 
    return isChanging; 
} 

使用PageMethod的調用它jQuery中:

var isAllowed = false; 
$("#edit").click(function() { 
    PageMethods.editFunc(); 
    PageMethods.checkRefresh(DisplayMyResult); //this line gives the error, though it's probably because it's first. 
}); 

function DisplayMyResult(ResultString) { 
    isAllowed = ResultString; 
    if (isAllowed == true || isAllowed == "true") { 
     location.reload(); 
    } 
    else { 
     PageMethods.checkRefresh(DisplayMyResult); 
    } 
} 

錯誤我得到(在鉻控制檯)是

Uncaught TypeError: Object function() { 
PageMethods.initializeBase(this); 
this._timeout = 0; 
this._userContext = null; 
this._succeeded = null; 
this._failed = null; 
} has no method 'checkRefresh' 

我不知道爲什麼它不工作,任何人都可以幫忙嗎?

+0

任何人......?幫幫我..? –

回答

3

而不是使用ScriptManager我想用jQuery調用頁面方法。請通過這篇不錯的文章Using jQuery to directly call ASP.NET AJAX page methods

[WebMethod] 
    public static string checkRefresh() 
    { 
    return isChanging; 
    } 


$.ajax({ 
    type: "POST", 
    url: "PageName.aspx/checkRefresh", 
    data: "{}", 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    success: function(msg) { 
    // Do something interesting here. 
    } 
}); 
+0

我該如何獲得checkRefresh()返回的布爾值? –

+0

沒關係,我明白了。謝謝=] –