jquery ajax object array php -


i have:

var apiquizdata = {'ect stuff removed...',answers:{}};     $.each(dataceactivequiz.quiz_data, function(index, answer) {         if(answer.selected == undefined){             apiquizdata.answers[answer.id] = 0;         } else {             apiquizdata.answers[answer.id] = answer.selected;         }     });      $.post(url, apiquizdata, function(data) { 

if @ form data submitted through header via chromes inspect tools shows:

// url decoded answers[28194]:112768 answers[28195]:112773 answers[28199]:112788 answers[28202]:112803 answers[28204]:112809  // url encoded answers%5b28194%5d:112768 answers%5b28195%5d:112773 answers%5b28199%5d:112788 answers%5b28202%5d:112803 answers%5b28204%5d:112809  // query string  answers%5b28195%5d=112773&answers%5b28199%5d=112788&answers%5b28202%5d=112803&answers%5b28204%5d=112809 

in php use

$sent_data = file_get_contents('php://input'); $sent_data_decoded = json_decode($sent_data, true); 

the string php receives

&answers=&answers=&answers=&answers=&answers=

what need data goes through php values?

thanks.

=================

update 1

if use

$.post(url, json.stringify(apiquizdata), function(data) { 

this sent

{...extra stuff...,"answers":{"28195":"112773","28199":"112791","28201":"112796","28202":"112800","28204":"112810"}} 

from php using json_decode(file_get_contents('php://input'), true);

{...extrastuff...}id%22%3a952077%2c%22answers%22%3a%7b%2228195%22%3a%22112

when print_r of data empty array?

=================

update 2 - working

updated jquery post

    $.post(url + 'sendcequizresults', {jsonstringify: json.stringify(apiquizdata)}, function(data) { 

updated php receiving code handle new way sending data old way

$sent_data = file_get_contents('php://input');              if(substr($sent_data, 0, 13) == 'jsonstringify')             {                 parse_str($sent_data);                 $sent_data_decoded = json_decode($jsonstringify, true);             } else             {                 $sent_data_decoded = json_decode($sent_data, true);             } 

for reason not work if didn't assign json.stringify(apiquizdata) value of object. browser seemed choke on text itself, guess because huge text string itself? not sure. either way above update #2 solved issues having.

thanks.

stringify object json string:

$.post(url, json.stringify(apiquizdata), function(data) { 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -