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();
})