PHP code does not execute and returns as a comment to HTML

Asked

Viewed 242 times

1

I have a code in javascript calling a file PHP:

$.post("subscript.php", {
  idPost: idPost
}, function(response2) {
  //Joga o resultado no lugar desejado.
  $("#respostaID").html(response2);
});

When this code responds, rather than bring the answer from PHP that was executed, it returns me the code of the commented subscript.php file inside the HTML mother-page.

Code PHP:

    <?php 

      $idPost = $_POST['idPost'];

      echo "<h1>".$idPost."</h1>";
    ?>

Answer I have after the reply from javascript:

<div id="respostaID" class="btn-group btn-group-justified pull-right"><!--?php 

  $idPost = $_POST['idPost'];

echo "<h1-->".$idPost."";

  	
?></div>

How to make my file on PHP execute and bring me only what I need?

Both files are in format .php

NOTE: These codes are being implemented together with a wordpress theme.

  • PHP works without being via ajax? IE, you can process PHP?

  • Take a look at the server, it is not processing PHP

  • Good guys, this is a gambit I’m doing inside a wordpress. php ta normal because I’m running wordpress.

1 answer

-1

The tag <?php needs to be right at the beginning of the line, can not have tab:

<?php 

  $idPost = $_POST['idPost'];

  echo "<h1>".$idPost."</h1>";
?>
  • The code is indented correctly in the file.

  • Leo, what’s the difference of having the <?php at first or not?

  • need to be at the beginning of the line to be interpreted as script

  • The place of the tag <?php makes no difference in this case. If so, PHP would not work in the middle of HTML code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.