Jquery提供了如下jQuery.when()函数。inquiryId在第一个呼叫中
$.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
});我怎么才能做到这一点?
发布于 2014-04-03 20:04:04
您不需要$.when,只需使用第一个请求的成功。
$.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查询.中。
发布于 2014-04-03 20:00:59
你可以用.then链接他们,先打个电话,然后再接第二个电话。在第一次呼叫之后,你可以在第二次呼叫中使用它的结果。
$.ajax({...}).then(function(){
return $.ajax({...});
}).then(function(){
return $.ajax({...});
}).then(function(){
return $.ajax({...});
}).then(function(){
return $.ajax({...});
});https://stackoverflow.com/questions/22847653
复制相似问题