weixin_33686714 2012-07-26 16:31 采纳率: 0%
浏览 24

使用ajax将vars发送到php

I can´t send variables to php with ajax with this function, but I can send them with a simple post directly to php and insert them to mysql.

I have test it with php and typical submit form action to the php file and works fine. I don´t know what I am missing. Thanks in advance. Best regards

<form class="largeform" id="editform" name="editform" accept-charset="utf-8"      action=""  onsubmit="enviarDatosEmpleado(); return false">   

any idea? // JavaScript Document 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;

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

  }
  • 写回答

2条回答 默认 最新

  • weixin_33724046 2012-07-26 16:37
    关注

    Try with jQuery:

    $.post("insert.php", {
        var: value,
        var2: value2
    }, function(responseText) {
        $("#resultado").html(responseText);
    });
    

    Make sure you include the jQuery library. You won't need to set up the connection ahead of time, FYI.

    评论

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入