Ejecutar funcion PHP con JQuery

Iniciado por edgar1912, Agosto 08, 2017, 02:14:56 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Agosto 08, 2017, 02:14:56 PM Ultima modificación: Agosto 09, 2017, 09:03:19 AM por Stiuvert
Tengo una duda, como puedo ejecutar una funcion de PHP con parámetros con un script de jquery ya lo intente pero no me imprime los valores de las variables agrego el codigo para que lo visualicen

Código: html5

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title></title>
  </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<?php
          function fn($a,$b){
              return $a.$b;
          }
    ?>
     <script>
function texto(){
var a=$("#a").val();
var b=$("#b").val();
document.write('<?php echo fn('a','b') ?>');
}
</script>
<input type="text" id="a" name="a">
<input type="text" id="b" name="b">
<input type="button" name="Release" onclick='texto();' value="Click to Release">

</body>
</html>


y en el resultado solo imprime esto:

ab

a,b son las variables que quiero que se despliege el vsalor

Encontre esto:

Citar<? php
    function func1($data){
        return $data+1;
    }

    if (isset($_POST['callFunc1'])) {
        echo func1($_POST['callFunc1']);
    }
?>

Citar$.ajax({
    url: 'myFunctions.php',
    type: 'post',
    data: { "callFunc1": "1"},
    success: function(response) { alert(response); }
});

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Trata de seguir ese ejemplo y comentas si funciona!
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login


You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Citar<input type='button' name='Release' onclick="downloadFichier(param1, param2)" value='Click to Release'>

Citarfunction downloadFichier(param1, param2){

        $.ajax({
            type: 'POST',
            url: 'file_product.php',
            data: "param1=" + param1 + "&param2=" + param2,
            success: function(data) {
                $("p").text(data);
            }
        });
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login


Eso es lo que me pareció al leerlo, mejor usar AJAX que JQuery :

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login