DOES NOT SAVE DATA IN AJAX

0

Hi, I wanted to know why it does not save my data when I'm using ajax

I created the function and put onclick on the button

<script>
function saveData(){
    var dni = $('#cli_dni').val();
    var nombres = $('#cli_nom').val();
    var apellidos = $('#cli_ape').val();
    var direccion = $('#cli_dir').val();
    var celular = $('#cli_cel').val();
    $.ajax({
        type: "POST",
        url: "conexion.php?p=add",
        data: "cli_dni="+dni+"&cli_nom="+nombres+"&cli_ape="+apellidos+"&cli_dir="+direccion+"&cli_cel="+celular,
    });
}
</script>

and then

<?php
$db = new PDO('mysql:host=localhost;dbname=systemfarma','root',''); 
$page = isset($_GET['p'])?$_GET['p']:'';
if($page=='add'){
    $dni = $_POST['cli_dni'];
    $nombres = $_POST['cli_nom'];
    $apellidos = $_POST['cli_ape'];
    $direccion = $_POST['cli_dir'];
    $celular = $_POST['cli_cel'];
    $stmt = $db->prepare("insert into clientes values('',?,?,?,?)");
    $stmt->$bindParam(1,$dni);
    $stmt->$bindParam(2,$nombres);
    $stmt->$bindParam(3,$apellidos);
    $stmt->$bindParam(4,$direccion);
    $stmt->$bindParam(5,$celular);
    $stmt->execute();
}else if($page=='edit'){

}else if($page=='del'){

}else{

}

? >

This is the new code that replaces the other but apparently does not work, my button goes out as blocked ... $ (document) .ready (function () {     load (1); });

$("#guardar_clientes").submit(function(event){
    $('#guardar_datos').attr("disabled", true);
    var parametros = $(this).serialize();
    $.ajax({
        type: "POST",
        url: "./ajax/registro_cliente.php",
        data: parametros,
        beforeSend: function(objeto){
            $("#resultado_ajax").html("Mensaje: Cargando...");
        },
            success: function(datos){
                $("#resultados_ajax").html(datos);
                $('#guardar_datos').attr("disabled", false);
                    load(1);
            }
    });
    event.preventDefault();
}) 
    
asked by Cristhian A. Villalobos Cuba 23.09.2017 в 09:09
source

1 answer

0

Check if you are receiving the data you send to the php, use var_dump for that. It is good that you comment on the error that you transmit when trying to save the information so you can have more information and be able to help you.

To send the information of a form via ajax I use the following procedure:

 $.ajax({

                type: "POST",
                url : varurl,
                datatype:'json',
                data : formu.serialize(),
                success : function(resul){
                 ...
                }

            });
    
answered by 23.09.2017 в 09:35