1
有沒有更好的寫下面的內容?有兩個服務電話的jquery ajax
我有兩個服務,我需要調用。
需要從第一個服務返回的數據來創建第二個Ajax調用的url。
$.ajax({
url: 'http://service',
type: 'GET',
dataType: 'json',
timeout: 1000,
error: function(){
alert('Error loading json document');
},
success: function(json){
processJson(json.foo);
}
});
function processJson(url) {
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
timeout: 1000,
error: function(){
alert('Error loading json document');
},
success: function(json){
displayJson(json.foo);
}
});
}
+1這是一個合理優雅的解決方案。 – cletus 2009-09-04 03:51:32