我不能用这个函数用ajax把变量发送到php,但我可以用一个简单的帖子直接把它们发送到php并将它们插入mysql。
我已经用 php 和典型的向 php 文件提交表单操作对其进行了测试,并且工作正常。我不知道我错过了什么。提前致谢。此致
<form class="largeform" id="editform" name="editform" accept-charset="utf-8" action="" onsubmit="enviarDatosEmpleado(); return false">
任何想法?// JavaScript 文档函数 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;
}
function enviarDatos(){
//donde se mostrará lo resultados
divresultado = document.getElementById('resultado');
//valores de los inputs
post_title=document.editform.post_title.value;
post_metad=document.editform.post_metad.value;
post_metak=document.editform.post_metak.value;
post_special=document.editform.post_special.value;
post_content=document.editform.post_content.value;
post_private=document.editform.post_private.value;
post_parent=document.editform.post_parent.value;
post_template=document.editform.post_template.value;
post_id=document.editform.post_id.value;
post_menu=document.editform.post_menu.value;
post_menu_order=document.editform.post_menu_order.value;
//instanciamos el objetoAjax
ajax=objetoAjax();
//uso del medotod POST
//archivo que realizará la operacion
//registro.php
ajax.open("POST", "insert.php",true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
//mostrar resultados en esta capa
divresultado.innerHTML = ajax.responseText
divresultado.innerHTML = "ok";
divresultado.style.display="block";
//llamar a funcion para limpiar los inputs
LimpiarCampos();
}
}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//enviando los valores
ajax.send ("post_title="+post_title+"&post_metad="+post_metad+"&post_metak="+post_metak+"&post_special="+post_special+"&post_content="+post_content+"&post_private="+post_private+"&post_parent="+post_parent+"&post_template="+post_template+"&post_id="+post_id+"&post_menu="+post_menu+"&post_menu_order="+post_menu_order)
// ajax.send("nombres="+nom+"&departamento="+dep+"&sueldo="+suel)
}