首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用jQuery.when()从第一个cal进行第二个调用

如何使用jQuery.when()从第一个cal进行第二个调用
EN

Stack Overflow用户
提问于 2014-04-03 19:53:38
回答 2查看 32关注 0票数 0

Jquery提供了如下jQuery.when()函数。inquiryId在第一个呼叫中

代码语言:javascript
复制
$.when( $.ajax( "http://localhost:50006/odata/Inquiry" ), $.ajax( "http://localhost:50006/odata/Inquiry?$filter=Id eq '" + inquiryIdFromTheFirstCall + "'" ) ).done(function( a1, a2 ) {
  // i want to get the id of an Inquiry from the fist call and make the second call with it 
});

我怎么才能做到这一点?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-03 20:04:04

您不需要$.when,只需使用第一个请求的成功。

代码语言:javascript
复制
$.ajax( "http://localhost:50006/odata/Inquiry" ).done(function(a1) {
    $.ajax("http://localhost:50006/odata/Inquiry?$filter=Id eq '" + a1 + "'").done(function(a2) {
        // do something with a2
    });
});

我希望url param不是直接插入到sql查询.中。

票数 1
EN

Stack Overflow用户

发布于 2014-04-03 20:00:59

你可以用.then链接他们,先打个电话,然后再接第二个电话。在第一次呼叫之后,你可以在第二次呼叫中使用它的结果。

代码语言:javascript
复制
    $.ajax({...}).then(function(){
        return $.ajax({...});
    }).then(function(){
        return $.ajax({...});
    }).then(function(){
        return $.ajax({...});
    }).then(function(){
        return $.ajax({...});
    });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22847653

复制
相关文章

相似问题

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