jquery - 通过ajax加载API结果

标签 jquery ajax jquery-load

我想知道 API 结果如何在响应到来时加载。

similar functionality

我认为使用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/

相关文章:

php - Yii2: Ajax 调用多个参数

在静态路由上使用 Express 进行 AJAX 抓取

javascript - 用 CSS 替代框架?

JavaScript:使用来自单独 HTML 文档的输入写入当前 HTML 文档?

javascript - 为什么我的变量在回调函数之外未定义?

jquery - 如果 span 为空则隐藏 div

javascript - ajax 和 $.getScript() 获取新脚本

c# mvc jquery 实时聊天

java - jquery 与 spring mvc 在 java 中

jquery - load() JSON 数据,生成 HTML 表格并将其放置在 div 内