使用瀏覽器調試工具並檢查PageMethods.GetCaseList中使用的自動生成的代碼,然後僅使用異步ajax調用而不是阻塞調用來模仿調用。
PageMethods包裝只是爲了方便,但代碼通常很醜。你可以隨時用$ .ajax或本機XmlHttpRequest手動調用它。
async = true;
如果您進行多次調用,ASP.NET會話可能會進行阻止。使用警報或CONSOLE.LOG的JavaScript方法中,以確定是什麼原因阻止
function get_case_list_data(count, max_id) {
console.log("before call");
PageMethods.GetCaseList(count, max_id, uid, is_agent, got_case_list_data, OnFailure);
console.log("after call");
}
function got_case_list_data(){
console.log("in PageMethod success");
// -- updated --
// this could be blocking the call to/from other 2 second timer
// JS is single thread, so window.timeout and ajax callbacks will
// wait until the function is exited
// -- end update--
console.log("end of PageMethod success");
}
- updated--
設置asp.net會話爲只讀去除獨佔會話鎖,將同步線程
所以基本上這些調用不是異步的? –
您可以在PageMethod調用之前和之後以及成功回調中使用警報來測試。谷歌「aysnc PageMethods」看起來可能是aysnc默認情況下,你需要進行更新,使其syncronouse。無論哪種方式,這個博客有一些很好的內容讓你開始。 http://abhijit-j-shetty.blogspot.com/2011/04/aspnet-ajax-calling-pagemethods.html – Steve
嘗試使用async = true的$ ajax;同樣的結果 –