2012-07-26 3 views
0

이 함수로 아약스로 변수를 보낼 수는 없지만 PHP로 직접 보내고 mysql에 삽입 할 수 있습니다.아약스로 phars에 vars 보내기

나는 그것을 PHP로 테스트 해본 결과 전형적으로 php 파일에 폼 액션을 보내고 잘 동작한다. 내가 뭘 놓치고 있는지 모르겠다. 미리 감사드립니다. 안부 인사

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

어떤 생각이 있으십니까? // 자바 스크립트 문서 기능 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) 

    } 
+0

충분하지 jQuery –

+1

jQuery 또는 mootools 또는 Prototype을 사용하십시오. 당신은 그들을 절실히 필요로합니다. – FatalError

+0

@webarto moar jquery가 필요합니다. – Lusitanian

답변

0

는 jQuery를 함께보십시오 :

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

당신이 jQuery 라이브러리를 포함해야합니다. 사전에 연결을 설정할 필요는 없습니다, 참고하시기 바랍니다.

0

양식의 DOM 요소를 제대로 참조하지 않았습니다. 하나의 주석이 언급 한 바와 같이, 당신이 정말로 아약스와 함께, 훨씬 더 쉽게 (그리고 더 상호 작동하게 jQuery를 같은 프레임 워크를 숙지해야한다 또한

document.getElementById('idOfFormElement').value 

:

당신이 뭔가를 할 필요가있을 것이다 브라우저 호환)