A variable sended from Ajax dissapears when entering directly to the PHP File -


i'm sending variable php via ajax.

the ajax triggered when keyup detected.

once keyup detected, catch value , name txtbx of keyup.

then, create request sends value , name of textbox triggered event.

in onreadystatechange launch function verify if ajax on, , if status 200 function retrieves me values of variables send, getting via echo of php side.

all ok till.

till go directly php page , variable sended client dissapear.

why, in moment of ajax mean when catch data/send/retrieve goes ok when go directly php, variable seems dissapear , pretty nice notice: undefined variable?.

here i'm sending code (it's spanish):

client side ajax request:

window.addeventlistener("load", iniciareventos, false); clase=""; function iniciareventos(e) {     var cajas = document.getelementsbyclassname(clase);     (var = 0; < cajas.length; i++) {         cajas[i].addeventlistener('keyup',obtenerdatos,false);     } }  function obtenerdatos(e) {     var ref=e.target;     var producto=ref.name;     var cantidad=ref.value; procesardat(producto,cantidad); } var conex3= new xmlhttprequest(); function procesardat(pro,can) {     conex3.onreadystatechange=procesarelementos;     conex3.open("get",'../procesarpedido/pruebaderecepcion.php?nombre='+pro+'&valor='+can,true);     conex3.send(null); }  function procesarelementos() {     if (conex3.readystate==4) {         alert(conex3.responsetext);     } } // goes pretty nice here! 

now server side :

    <?php session_start(); if (isset($_request['nombre'])) {         $nombre=$_request['nombre'];     }     if (isset($_request['valor'])) {         $valor=$_request['valor'];     }     if (isset($_session['orden'])) {         $_session['orden']=array();         $_session['orden'][$nombre]=$valor;         $nuevaord= new nuevaorden($_session['orden']);         $nuevaord->validarorden();     }else {         $_session['orden'][$nombre]=$valor;         $nuevaord= new nuevaorden($_session['orden']);         $nuevaord->validarorden();     }     class nuevaorden{         private $arreglo;         public function __construct($ar){             $this->arreglo=$ar;             $this->empujarorden();         }         private function empujarorden() {             foreach ($_session['orden'] $nom => $val) {                 if ($val=="") {                     unset($this->arreglo[$nom]);                 }             }         }     public function validarorden(){         $arr=json_encode($this->arreglo);         echo $arr;     }     }     ?> 

the data (variable) sending exists in context of request, - while making request. when load page browser, launch page in new context. in same way, if made new ajax call, old variable not exist.

instead, if want access page directly, can either put desired variables in or send them via html form's post, so:

yourpath.com/procesarpedido/pruebaderecepcion.php?nombre=pro variable value&valor=can variable value


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -