0

The issue I'm having is that when I'm attempting to post to a PHP page it will just return the entire PHP document and not the things being echoed.

 <script type="text/javascript">
    $.ajax({ type:"POST",
             url:"backMap/locationCreation.php",
             data: { name: "TEMP" },
             success: function(data) { $("#awesomet").html(data);},
             error: function(xhr, textStatus, thrownError, data) {
                alert("Error: " + thrownError); 
             }
    });
 </script>
 <div id="awesomet">Not showing.</div>

With this I am trying to send an Ajax Post to the given URL. I am giving it some data and if it returns successfully then it will put it's data within the div.

 <?php
   if (isset($_GET['name'])) {
       echo "Asked for name!";
   }
   for ($i = 1; $i <= 10; $i++) {
      echo '<p>For loop! Value: ' . $i . ' of 10.</p>';
   }
 ?>

When I call this I receive the entire php page as a result.

I literally get the whole page, if statements, for loop and all. Including the <?php flags. I don't understand why I'm receiving the data like this.

I am running this through Phonegap.

Any help is appreciated.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
Jake Alsemgeest
  • 692
  • 2
  • 13
  • 25

2 Answers2

1

If you see the entire php file including the PHP declaration, this might point to a problem with your webserver configuration. Maybe your webserver does not recognize files ending on .php as PHP files.

actc
  • 672
  • 1
  • 9
  • 23
0

Try this

 <script type="text/javascript">
    $.ajax({ type:"POST",
             url:"backMap/locationCreation.php",
             data: { name: "TEMP" },
             dataType : 'json',
             success: function(data) { $("#awesomet").html(data.return);},
             error: function(xhr, textStatus, thrownError, data.return) {
                alert("Error: " + thrownError); 
             }
    });
 </script>

And in the php

 if (isset($_POST['name'])) {
   $a =array();
   $a['return'] = "Asked for name!";
   echo json_encode($a);
 }

Also, you have to check your Apache configuration, because you are getting somehow the .php file

MayTheSchwartzBeWithYou
  • 1,181
  • 1
  • 16
  • 32