How to send JavaScript collection to PHP variable? -


i trying send data form php file using javascript. php file pushes data database. now, works have problem array getelementsbyclassname. after sending database can see "array" no values of array.

here's js:

function przekaz_form($wejscie) {     var datas = document.formularz.datas.value;     var klient = document.formularz.firma.value;     var comment = document.formularz.comment.value;     var collect = document.getelementsbyclassname($wejscie);           var datan = document.formularz.datan.value;      var items = new array();     for(var = 0; < collect.length; i++) {         items.push(collect.item(i).value);     }       jquery.ajax({         url: 'addtobase.php',         type: 'post',         data:{             devices: items,             datas: datas,             klient: klient,             comment: comment,             datan: datan          },         success: function(output) {           alert('success');         }     }); } 

one way is:

$inputdata = json_decode(file_get_contents('php://input')); 

once have $inputdata variable can access data in json by:

$devices = (!is_null($inputdata) && property_exists($inputdata, "devices")) ? strip_tags($inputdata->{"devices"}) : 0; 

you should try better format json : http://json.org/example


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -