使用PHP和jquery在单个处理函数中一个接一个地调用两个ajax


making two ajax call one after other in single handler function using php and jquery

我想写一个文件three.php加载one.php和two.php一个接一个,即two.php应该在one.php收到后加载。这应该在点击three。php

中的按钮后发生

my code for one.php

<?php
header("Content-type: image/png");
$image = imagecreatetruecolor(800, 700);
$red = imagecolorallocate($image, 250, 0, 0);
imagefilledellipse($image,10,10,10,10, $red);
imagepng($image);
?>
php
<?php
header("Content-type: image/png");
$image = imagecreatetruecolor(800, 700);
$red = imagecolorallocate($image, 250, 0, 0);
imagefilledellipse($image,10,10,10,10, $red);
imagepng($image);
?>

所以three。PHP的代码应该是这两个PHP文件使用两个不同的按钮

你的代码应该是这样的:

文件three.php

    <script type="text/javascript" src="<path to jquery>"></script>
    <button onclick="loadFiles()"></button>
    <script type="text/javascript">

        function loadFiles(){
              $.ajax({
                    type : 'GET',
                    url : '/one.php/',
                    data : {}
                    success :function(data)
                    {
                            //file one content is available in data 
                            //now calling for file2
                            $.ajax({
                                  type : 'GET',
                                  url : '/two.php/',
                                  data : {}
                                  success :function(file2Data)
                                  {
                                   //file2 available here
                                  },
                                  error : function(data)
                                   {
                                   //error handling code here
                                  }
                            });
                    },
                    error : function(data)
                    {
                        //error handling code here
                    }
                });
            }
     </script>