Código:
mis codigos php // JavaScript Document
var xmlhttp;
function load(str, url, cfunc)
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=cfunc;
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(str);
}
function metodoAjax(datos, ruta)
{
load(datos, ruta, function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("cuerpo").innerHTML=xmlhttp.responseText;
}
});
}
function enviarDatos(){
var fecha="", licencia="", fechaaut="", idcliente="", nombre="", domicilio="", telefono="", poblacion="", datos="";
fecha = document.getElementById("fecha").value;
licencia = document.getElementById("licencia").value;
fecha_aut = document.getElementById('fecha_aut').value;
nombre = document.getElementById("nombre").value;
domicilio = document.getElementById("domicilio").value;
telefono = document.getElementById("telefono").value;
poblacion = document.getElementById("poblacion").value;
datos="var_fecha="+fecha+"&var_licencia="+licencia+"&var_fechaaut="+fecha_aut+"&var_nombre="+nombre+"&var_fecha="+fecha+"&var_domicilio="+domicilio+"&var_telefono="+telefono+"&var_poblacion="+poblacion;
metodoAjax(datos,"./control/controlador.php");
}
Código PHP:
<?php
require "../modelo/modelo.php";
$objRegistrar = new Registrar();
if(isset($_POST["var_fecha"]) && isset($_POST["var_licencia"]) && isset($_POST["var_fechaaut"]) && isset($_POST["var_nombre"]) && isset($_POST["var_domicilio"]) && isset($_POST["var_telefono"]) && isset($_POST["var_poblacion"])){
$objRegistrar->registrarPersona($_POST["var_fecha"], $_POST["var_licencia"], $_POST["var_fechaaut"], $_POST["var_nombre"], $_POST["var_domicilio"], $_POST["var_telefono"], $_POST["var_poblacion"]);
//echo $_POST["var_nombre"]." ".$_POST["var_domicilio"];
}
?> Código PHP:
<?php
require "../conexion/conexion.php";
class Registrar{
var $conn;
var $conexion;
var $mensajeExito;
var $mensajeError;
function Registrar(){
$this->conexion= new Conexion();
$this->conn=$this->conexion->conectarse();
$this->mensajeExito="Registro Exitoso";
$this->mensajeError="Error al Registrar";
}
//---------------------------------------------------------------------------------------------------------------------------
function registrarPersona($fecha, $licencia, $fechaaut, $nombre, $domicilio, $telefono, $poblacion){
$queryRegistrar = "insert into licencias (fecha, licencia, fechaaut, nombre, domicilio, telefono, poblacion) values ('".$fecha."', '".$licencia."', '".$fechaaut."', '".$nombre."', '".$domicilio."', '".$telefono."', '".$poblacion."')";
$registrar = mysqli_query($this->conn, $queryRegistrar) or die(mysqli_error());
if($registrar){
echo $this->mensajeExito;
}else{
echo $this->mensajeError;
}
}
}
?>

es más fácil usar Ajax sin librerías
, yo lo he hecho siempre...


