2010-10-07 98 views
1

我接受C#和VB.NET使AJAX調用回ASP.NET中使用jQuery

如果你訪問這個http://www.eol.org/pages/983558,然後單擊像圖像的鏈接下面你會看到在 - 在顯示信息之前顯示Ajax回調的繁忙狀態的在線彈出式DIV。所以,直到你點擊鏈接,信息纔會出現。

alt text

我想要做相同的,但ASP.NET和jQuery。如果有什麼地方可以幫助我開始正確的道路?謝謝。

回答

3

Using jQuery to directly call ASP.NET AJAX page methods

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

我覺得這可能是一個良好的開端。

0

是的,你可以使用roberts代碼發送ajax請求到服務器端代碼,另外你可以使用beforeSend callbck函數,其中你將顯示你的隱藏div與加載..消息和成功函數,你會實際上把數據放入DIV。

$.ajax({ 
    type: "POST", 
    url: "PageName.aspx/MethodName", 
    data: "{}", 
    beforeSend: function() 
    { 
    //display hidden div with loading.. message 
    }, 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    success: function(msg) { 
    // remove loading.. message and put actual data to the div 
    } 
}); 

如果由於某種原因ajax調用失敗,您可以使用錯誤回調在同一個div中顯示錯誤消息。您可以瞭解更多關於$ .ajax功能的信息here