Run Javascript commands by PHP

Asked

Viewed 104 times

-1

I have the following problem, I cannot run Javascript commands from PHP.

Page check time.php

<?php
  echo 'alert("teste")';
?>

Page index php.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>
$.ajax({
    url: 'verificar-horario.php',
    type: 'GET',
    data: dados,
    success: function (data) {
       return data;
   }
});
</script>

2 answers

0


has to include the function to work

<?php
  include "verificar-horario.php";
?>

Edit: wait... reading better I did not understand what your intention in creating a alert this way... If you were to simulate a data that would come from php, wouldn’t it be simpler to pass directly? (i.e., without javascript)

  • I actually put an Alert as an example, but actually I’d like to call another code.

  • I understand, that answer here is quite complete about https://answall.com/a/58965/139524

0

Just put it this way:

<?= ("<script>alert('teste')</script>");?>

Open the php tags, close and then put the script, this example does not bring us the scope of need... can not help much. That question is a little pointless...

But it will be totally outside the recommended standards. Search separates files by type and include them following good programming practices.

Browser other questions tagged

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