【发布时间】:2010-05-07 11:16:36
【问题描述】:
我在 asp.net 中开发了一个 Web 应用程序。在这个应用程序中,我在某些页面上使用了 jquery ajax。在这个应用程序中,当我异步进行两个 ajax 调用时,这不会像我预期的那样。发生的事情甚至是第二个 ajax 调用完成我可以在最大超时 ajax 调用完成时看到结果。我的意思是我可以同时看到这两个结果,而不是一个一个。
举个例子。我有 3 页
main.aspx - 用于发出两个 ajax 请求。
totalCount.aspx - 查找总计数。 (最多需要 7 秒才能返回,因为对应的表包含 30 万条记录)
rowCount.aspx - 查找行详细信息。 (返回结果最多需要 5 秒)。
由于这个场景,我计划在 asp.net 中的 jquery ajax 中进行 asyn 调用。 这是我的代码:
function getResult() {
getTotalCount();
getRows();
}
// it takes max 7 seconds to complete
// as it take 7 seconds it should display second.( I mean after the rows dispaying)
// but displaying both at the same time after the max time consuming ajax call completed.
function getTotalCount() {
$.ajax({
type : "POST",
async : true,
url : "totalCount.aspx?data1=" + document.getElementById("data").value,
success : function(responseText) {
$("#totalCount").attr("value", responseText);
}
})
}
// it takes max 5 seconds to complete.
// after finished, this should display first.( i mean before total count displays)
// but displaying both at the same time after the max time consuming ajax call completed.
function getRows() {
$.ajax({
type : "POST",
url : "getrows.aspx?data1=" + document.getElementById("data").value,
async : true,
success : function(responseText) {
$("#getRows").attr("value", responseText);
}
});
}
我想知道,如果有可能在 asp.net 中的 jquery ajax 中进行异步调用。 我在网上搜索,我得到了一些点说我们不能在 asp.net 中这样做
参考链接:http://www.mail-archive.com/jquery-en@googlegroups.com/msg55125.html
如果我们可以在asp.net中做到这一点怎么做?
【问题讨论】:
标签: javascript asp.net jquery ajax asynchronous