是否可以在另一个ajax请求中发出一个ajax请求? 因为我需要第一个 ajax 请求中的一些数据来发出下一个 ajax 请求。
首先,我使用 Google Maps API 获取 LAT 和 LNG,然后使用该 LAT 和 LNG 请求 Instagram API(基于搜索的位置)。
再说一次,这可能吗?如果可能的话,如何实现?
$('input#search').click(function(e) {
e.preventDefault();
var source = $('select[name=state] option:selected').text()+' '+$('select[name=city] option:selected').text()+' '+$('select[name=area] option:selected').text();
var source = source.replace(/ /g, '+');
if(working == false) {
working = true;
$(this).replaceWith('<span id="big_loading"></span>');
$.ajax({
type:'POST',
url:'/killtime_local/ajax/location/maps.json',
dataType:'json',
cache: false,
data:'via=ajax&address='+source,
success:function(results) {
// this is where i get the latlng
}
});
} else {
alert('please, be patient!');
}
});
最佳答案
这是一个例子:
$.ajax({
type: "post",
url: "ajax/example.php",
data: 'page=' + btn_page,
success: function (data) {
var a = data; // This line shows error.
$.ajax({
type: "post",
url: "example.php",
data: 'page=' + a,
success: function (data) {
}
});
}
});
关于Ajax 请求中的 jQuery Ajax 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10089447/