1

I want to write a file three.php which loads one.php and two.php one after other, i.e. two.php should load after one.php is received. And of this should happen after clicking a button present in 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);

?>

code for two.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);

?>

so help with the code of three.php which should these two php files using two different buttons

3
  • 1
    what should it do via ajax , download the image or use it in something ? Commented Sep 1, 2016 at 18:06
  • Do you need to embed the contents of these pages into three.php, or do you need to open them in a new window/tab? Commented Sep 1, 2016 at 18:07
  • yes! i need to embed the contents of these pages into three.php and in div elements. Commented Sep 1, 2016 at 19:08

1 Answer 1

2

Your code would ideally look like this :

File 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>
Sign up to request clarification or add additional context in comments.

4 Comments

It doesnt work . A i implement the above code the image created by the files one.php and two.php arent displaying .Can you help me with exact code .The code i written was
The files on.php and two.php should generate the image files when i click on buttons ,but they arent generating.
Thanks in advance!
@abhinist can you please send me the answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.