Me gustaría obtener el valor de ajax con la publicación en php, pero esto no funciona, aquí está mi código:
<script type="text/javascript"> function deletarPerson(id_person) { let pag = "<?php echo plugin_dir_url(__DIR__) . 'admin/'; ?>"; jQuery.ajax({ url: pag + "/config.php", method: "post", data: { id_person: id_person }, dataType: "html", success: function(result) { <?php $aux = $_POST['id_person']; ?> alert('<?php echo $aux ?>') }, }) } </script>¿Puede ayudarme alguien?
Su código Javascript ajax:
function deletarPerson(id_person) { jQuery.ajax({ url: "/echo.php", // <-- sending to echo.php on the server // ...use whatever PHP file, on the server, // you need to get the necessary information method: "post", data: { id_person: id_person }, dataType: "text", success: function(result) { alert(result) // <-- now use Javascript and the result variable, // which is text sent back from the server, // and do what you need to with it on the client }, }) }... y su archivo PHP:
<!-- echo.php --> <?php $aux = $_POST['id_person']; echo $aux; // <-- whatever is echo'ed or print'ed in this file // gets sent back to the server as text // and is loaded in the Javascript result variable // OR you can actually get some useful information from the server // and send that back instead ?>Lea más sobre los distintos contextos de ejecución entre PHP en el servidor y Javascript/HTML/CSS... en el cliente .