首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对3个Web服务的AJAX调用

对3个Web服务的AJAX调用
EN

Stack Overflow用户
提问于 2013-07-16 07:52:48
回答 1查看 58关注 0票数 0

我正在尝试将3个ajax调用转换为一个,但目前我只得到一个。这就是我要做的:

代码语言:javascript
复制
$.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);
    }
}),

现在,我希望能够调用这三种方法,但目前只有一种方法:

代码语言:javascript
复制
$(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中我有:

代码语言:javascript
复制
<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_twohpl_three的语法,非常感谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-16 07:57:10

我能想到的最快..。创建一个包含所有三个调用的函数并调用该函数

代码语言:javascript
复制
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);
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17670963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档