javascript - AJAX post method: Variables are not passed to target php -


i trying send 2 pieces of info php. 1-) tent = zuzu 2-) zart = gagi

target php echoes send can check if it's working. javascript:

    function boka () { var mesparam = "tent=zuzu&zart=gagi"; if (window.xmlhttprequest){xmlhttp=new xmlhttprequest();} else {xmlhttp=new activexobject("microsoft.xmlhttp");} xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) {document.getelementbyid("response").innerhtml=xmlhttp.responsetext;} } xmlhttp.open("post","/mysite/oxifa/oxifat.php?tent=zuzu&zart=gagi",true);  //xmlhttp.setrequestheader("content-type", "application/x-www-form-urlencoded"); //xmlhttp.setrequestheader("content-length", mesparam.length); //xmlhttp.setrequestheader("connection", "close"); xmlhttp.send(mesparam); } 

this oxifat.php recieves request:

    <?php echo " sign1 <br>";   echo next($_post); echo next($_post); echo next($_post); echo next($_post); echo next($_post); echo $_post['tent']; echo $_post['zart']; echo $_request['tent']; echo $_request['zart'];  echo "<br> sign2";  ?> 

as can see i've included sorts of things echo out whatever in $_post apparently there nothing there , response get:

sign1

notice: undefined index: tent in c:\wamp\www\mysite\oxifa/oxifat.php on line 16

notice: undefined index: zart in c:\wamp\www\mysite\oxifa/oxifat.php on line 17

notice: undefined index: tent in c:\wamp\www\mysite\oxifa/oxifat.php on line 18

notice: undefined index: zart in c:\wamp\www\mysite\oxifa/oxifat.php on line 19

sign2

three lines "setrequestheader" in comment status. if include them, don't sign1. no response. figure out ok don't seem understand how use post method pass data php. how do this? have read on net. not know "setrequestheader" for. 1 more thing: if put ?tent=zuzu&zart=gagi @ end of target url, $_request thing works. that's , not i'm trying do. $_post's deal?

could please try invoke following code

function getxmlobject() {   var xmlhttp = false;   try {     xmlhttp = new activexobject("msxml2.xmlhttp");// old microsoft browsers   }   catch (e) {     try {       xmlhttp = new activexobject("microsoft.xmlhttp");// microsoft ie 6.0+     }     catch (e2) {       xmlhttp = false;// no browser accepts xmlhttp object false     }   }   if (!xmlhttp && typeof xmlhttprequest != 'undefined') {     xmlhttp = new xmlhttprequest();//for mozilla, opera browsers   }   return xmlhttp;// mandatory statement returning ajax object created }  var xmlhttp = new getxmlobject();//xmlhttp holds ajax object  //use method asynchronous communication function dorequest(params, callback) {   if (xmlhttp) {     xmlhttp.open("post", "your_script.php?" + params, true);     xmlhttp.onreadystatechange = function () {       if (xmlhttp.readystate == 4) {         if (xmlhttp.status == 200) {           callback(xmlhttp.responsetext);         }         else {           alert("error retrieving information (status = " + xmlhttp.status + ")\n" + response);         }       }     };     xmlhttp.setrequestheader('content-type', 'application/x-www-form-urlencoded');     xmlhttp.send(null);   } } 

and in php script first thing off write

print_r($_post); 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -