我正在尝试将3个ajax调用转换为一个,但目前我只得到一个。这就是我要做的:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Ws.aspx/One",
dataType: "json",
success: function (result1) {
$('#hpl_one').html(result1.d);
}
}),
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Ws.aspx/Two",
dataType: "json",
success: function (result2) {
$('#hpl_two').html(result2.d);
}
}),
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Ws.aspx/Three",
dataType: "json",
success: function (result3) {
$('#hpl_three').html(result3.d);
}
}),现在,我希望能够调用这三种方法,但目前只有一种方法:
$(document).ready(function () {
var refreshId = setInterval(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Ws.aspx/One",
dataType: "json",
success: function (result1) {
$('#hpl_one').html(result1.d);
}
});
// end calling ajax to count alert
}, 3000);
});在HTML中我有:
<a id="hpl_one" runat="server">---</a>
<a id="hpl_two" runat="server">---</a>
<a id="hpl_three" runat="server">---</a>我可以得到hpl_one,但是我不知道在success子句中调用hpl_two和hpl_three的语法,非常感谢。
发布于 2013-07-16 07:57:10
我能想到的最快..。创建一个包含所有三个调用的函数并调用该函数
function makeAjax()
{
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Ws.aspx/One",
dataType: "json",
success: function (result1) {
$('**#hpl_one**').html(result1.d);
}
}),
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Ws.aspx/Two",
dataType: "json",
success: function (result2) {
$('**#hpl_two**').html(result2.d);
}
}),
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Ws.aspx/Three",
dataType: "json",
success: function (result3) {
$('**#hpl_three**').html(result3.d);
}
})
}
$(document).ready(function () {
var refreshId = setInterval(makeAjax, 3000);
});https://stackoverflow.com/questions/17670963
复制相似问题