PHP being commented within JS

Asked

Viewed 77 times

-2

The code is this:

   success: function (result) {
      var tbody = $('tbody');
      tbody.html('');

      $.each(result, function(k, value) {
        search += "<tr class='tagtr'>";
          search += "<td>" + value.description + "</td>";
          search += "<td>" + value.initial + "</td>";
          search += "<td>" + value.email + "</td>";
          search += "<td>" + value.url + "</td>";
          search += "<td id='table_status' class='text-center'><?= convertStatus(" + value.status + "); ?></td>";
          search += "<td class='text-center'>";
            search += "<button class='btn btn-red-dark' onclick='location=\"alter?q=" + value.id + "\"'><span class='glyphicon glyphicon-edit' aria-hidden='true'></span></button>";
          search += "</td>";
        search += "</tr>";
      });

      tbody.append(search);
   },
   error: function(result) {
      $('#alert').addClass('alert alert-danger').html().show('100');
   }
});

inserir a descrição da imagem aqui

What can I do to stop commenting???

  • use <?php tag ?>

  • I tried it didn’t work.

1 answer

7

This will not work. PHP is processed by the Server, while Javascript code in this case is processed by the Client (Browser). You can create a looping in PHP to write Javascript code, but it is not possible to do the reverse (which is your case). Either you make an AJAX request to the Server asking to run this function in PHP or you create a function in Javascript to be called instead of trying to call PHP functions.

Browser other questions tagged

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