1

i created a js function which gets called by certain action,

var getX3DListFromServer = function()
{
  var dataList;
 //var post = $.post('X3DHandling.php', {postState:"getList"}, 
 //function(data){
 //  dataList = data;
 //});
 //console.log(dataList);
 //
  $.ajax({
    type: 'POST',
    url: 'X3DHandling.php',
    data: {postState:"getList"},
    success: function(data){$('#result').html(data);},
    error: function(){alert('getting list error')},
  });

  return dataList;
}

the php contains the following code,

<?php
echo "Working";
?>

I thought that the string gets pushed into the div but instead the variable data contains the complete php. It seems like the php file got not intepreted in an appropiate way.

<div id="result" class="footer"><!--?php
echo "Working";
?--></div>

I did everything what other people described in videos or different entries - but I don't know what I did wrong.

I hoped to get a result like this:

<div id="result" class="footer">
echo "Working";
</div>

I hope you can help me - thank you for your time.

Synaps
  • 323
  • 5
  • 14

1 Answers1

-1

Do Something like:

$.ajax({
     type: "POST",
     url: "functions.php",
     data: {
        products: "products",
      },
      success: function (data) {
       console.log("received data: " + data);
      },
      error: function (err) {
       alert('error: ' + err);
      }
}); //END AJAX CALL

And in the PHP:

if (isset($_POST['products'])) {
  $MyProducts = $_POST['products'];
   //PHP FUNCTION CALL HERE FOR EXAMPLE
}
NickVH
  • 143
  • 1
  • 11