Jquery 将ajax调用到另一个ajax
我有两个ajax,我想互相调用 如果我的第一个ajax是:Jquery 将ajax调用到另一个ajax,jquery,ajax,integration,Jquery,Ajax,Integration,我有两个ajax,我想互相调用 如果我的第一个ajax是: xhrAddressPoll = $.ajax({ url: api, data: { address: address, longpoll: longpoll }, dataType: 'json', cache: 'false', success: function(data){ updateText('yourHashes', (d
xhrAddressPoll = $.ajax({
url: api,
data: {
address: address,
longpoll: longpoll
},
dataType: 'json',
cache: 'false',
success: function(data){
updateText('yourHashes', (data.stats.hashes || 0).toString());
updateText('yourPaid', (data.stats.paid));
},
});
如果我的第二个ajax是:
$.ajax({
url: CoinPriceAPI,
dataType: 'json',
cache: 'false'
}).done(function(data1) {
coinPrice = data;
updateText('coinPriceBTC', coinPrice.price );
});
我的两个ajax如何相互调用
我想要的输出示例如下:
updateText('yourPaidBTC', (data.stats.paid * coinPrice.price));
xhrAddressPoll = $.ajax({
url: api,
data: {
address: address,
longpoll: longpoll
},
dataType: 'json',
cache: 'false',
success: function(data){
updateText('yourHashes', (data.stats.hashes || 0).toString());
updateText('yourPaid', (data.stats.paid));
updateText('yourPaidBTC', (data.stats.paid * coinPrice.price));
},
});
function ajax1() {
$.ajax({
...
success: function(ajax1Data) {
ajax2(ajax1Data);
}
});
}
function ajax2(ajax1Data) {
// call your second ajax here
}
如果我喜欢这个:
updateText('yourPaidBTC', (data.stats.paid * coinPrice.price));
xhrAddressPoll = $.ajax({
url: api,
data: {
address: address,
longpoll: longpoll
},
dataType: 'json',
cache: 'false',
success: function(data){
updateText('yourHashes', (data.stats.hashes || 0).toString());
updateText('yourPaid', (data.stats.paid));
updateText('yourPaidBTC', (data.stats.paid * coinPrice.price));
},
});
function ajax1() {
$.ajax({
...
success: function(ajax1Data) {
ajax2(ajax1Data);
}
});
}
function ajax2(ajax1Data) {
// call your second ajax here
}
我犯了以下错误:
货币价格没有定义
谢谢你的帮助 如果我正确理解了你的问题,你想做这样的事情:
updateText('yourPaidBTC', (data.stats.paid * coinPrice.price));
xhrAddressPoll = $.ajax({
url: api,
data: {
address: address,
longpoll: longpoll
},
dataType: 'json',
cache: 'false',
success: function(data){
updateText('yourHashes', (data.stats.hashes || 0).toString());
updateText('yourPaid', (data.stats.paid));
updateText('yourPaidBTC', (data.stats.paid * coinPrice.price));
},
});
function ajax1() {
$.ajax({
...
success: function(ajax1Data) {
ajax2(ajax1Data);
}
});
}
function ajax2(ajax1Data) {
// call your second ajax here
}
至于您的“coinPrice未定义”错误,听起来您处于严格模式下很好!但是您没有可以在函数之间共享的全局coinPrice变量。您认为a调用B和B调用a是什么意思?是的,第一个ajax可能重复,第二个ajax可以调用