我想知道 API 结果如何在响应到来时加载。
我认为使用ajax从数据库中我们可以得到。 但这里来自 API(实时结果)SOAP API。
有什么建议吗?
编辑
我当前的ajax函数是
$.ajax({
type: "get",
url: "<?=base_url()?>search/showresults",
cache: false,
data:datastring,
beforeSend:function(){
$('#resultloader').show();
},
success: function(response){
$('#resultloader').hide(500);
$('#showflightresults').html(response);
},
error: function(){
//alert('Error while Sending request..');
}
});
谢谢
最佳答案
尝试将 dataType 设置为 xml
并将 processData 设置为 false
并检查。
$.ajax({
type: "get",
url: "<?=base_url()?>search/showresults",
cache: false,
data:datastring,
processData: false,
dataType:"xml",
beforeSend:function(){
$('#resultloader').show();
},
success: function(response){
$('#resultloader').hide(500);
$('#showflightresults').html(response);
},
error: function(){
//alert('Error while Sending request..');
}
});
编辑:-
您需要迭代 php 数组。
var arrayFromPHP = <?php echo json_encode($arrayPHP) ?>;
$.each(arrayFromPHP, function (i, elem) {
// do your stuff
});
关于jquery - 通过ajax加载API结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22375306/