function objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
//INGRESAR DATOS
function Registrar(){
titulo = document.frmArticulos.titulo.value;
extracto = document.frmArticulos.extracto.value;
texto = document.frmArticulos.texto.value;
thumb = document.frmArticulos.thumb.value;
ajax = objetoAjax();
ajax.open("POST", "../admin/nuevo.php", true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
alert('Los datos fueron guardados con exito!');
window.location.reload(true);
}
}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send("titulo="+titulo+"&extracto="+extracto+"&texto="+texto+"&thumb="+thumb);
}
<?php session_start();
require 'config.php';
require '../functions.php';
comprobarSession();
$conexion = conexion($bd_config);
if (!$conexion) {
header('Location: ../error.php');
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$titulo = limpiarDatos($_POST['titulo']);
$extracto = limpiarDatos($_POST['extracto']);
$texto = $_POST['texto'];
$thumb = $_FILES['thumb']['tmp_name'];
$archivo_subido = '../' . $blog_config['carpeta_imagenes'] . $_FILES['thumb']['name'];
move_uploaded_file($thumb, $archivo_subido);
$archivo_subido
$statement = $conexion->prepare(
'INSERT INTO articulos (id, titulo, extracto, texto, thumb)
VALUES (null, :titulo, :extracto, :texto, :thumb)'
);
$statement->execute(array(
':titulo' => $titulo,
':extracto' => $extracto,
':texto' => $texto,
':thumb' => $_FILES['thumb']['name']
));
header('Location: '. RUTA . '/admin');
}
?>
function Conectar()
{
if(window.XMLHttpRequest)
Conexion=new XMLHttpRequest(); //mozilla
else if(window.ActiveXObject)
Conexion=new ActiveXObject("Microsoft.XMLHTTP"); //microsoft
return Conexion;
}