Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何根据php脚本的功能制作一个php/ajax脚本来显示文本_Php_Ajax_Loading Image - Fatal编程技术网

如何根据php脚本的功能制作一个php/ajax脚本来显示文本

如何根据php脚本的功能制作一个php/ajax脚本来显示文本,php,ajax,loading-image,Php,Ajax,Loading Image,因此,我有一个正在编写的脚本,其中包含对另一个php文件的ajax调用,该文件从api中提取数据。api脚本有三个不同的函数。因此,当调用ajax时,我让它显示加载图像,但我也希望它显示文本,这取决于api脚本正在运行的函数 这就是我现在用的 <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <script type="text/javascript" src="http://code.j

因此,我有一个正在编写的脚本,其中包含对另一个php文件的ajax调用,该文件从api中提取数据。api脚本有三个不同的函数。因此,当调用ajax时,我让它显示加载图像,但我也希望它显示文本,这取决于api脚本正在运行的函数

这就是我现在用的

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script>
function loadingAjax(div_id) {
      var divIdHtml = $("#"+div_id).html();
      $.ajax({
           type: "POST",
           url: "testmash.php?tag=<? echo $ptag; ?>",
           data: "tag=John&id=28",
           beforeSend: function() {
              $("#loading-image").show();
           },
           success: function(msg) {
              $("#"+div_id).html(divIdHtml + msg);
              $("#loading-image").hide();
           }
      });
}
</script> 
<body onLoad="loadingAjax('myDiv');">
    <div id="myDiv" style="margin-top:500" align="center">
        <img id="loading-image" src="ajax-loader.gif" style="display:none;"/>
    </div>
</body>

函数加载jax(div_id){
var divIdHtml=$(“#”+div_id).html();
$.ajax({
类型:“POST”,
url:“testmash.php?tag=”,
数据:“tag=John&id=28”,
beforeSend:function(){
$(“#加载图像”).show();
},
成功:功能(msg){
$(“#”+div_id).html(divIdHtml+msg);
$(“#加载图像”).hide();
}
});
}

因此,在加载testmash.php文件时,我想显示我的ajax-loader.gif,并在函数1完成且函数2启动后显示一条消息,其中显示函数1的“blah blah blah blah”,显示一条新消息,说“我们正在执行函数2”在调用ajax时,我有很多函数,甚至像一个检查表,有一个包含三个函数的列表,作为完整的函数,有一个绿色的复选标记,或者在完成之前不会在它旁边显示什么。我希望这是有意义的。

在“myDiv”中添加一个div,用id“message”调用它,并在调用函数时用javascript相应地更改它

$('#ajaxMessage').html('My message');

希望这能回答您的问题。

我想您应该使用嵌套回调函数