Cant Post JSON Object using Jquery.post()

NDH

New Member
I have the following object that gets created in my javascript application.\[code\] poll_data[active_question] = { 'question': $('div.question_wrap textarea').attr('value'), 'answers': [ $('div.answer_wrap input#0').attr('value'), $('div.answer_wrap input#1').attr('value'), $('div.answer_wrap input#2').attr('value'), $('div.answer_wrap input#3').attr('value'), $('div.answer_wrap input#4').attr('value'), $('div.answer_wrap input#5').attr('value') ] };\[/code\]active_question is set to 'poll', 0, 1, 2, 3, 4, or 5 depending on the question being worked on at the moment. I am trying to post this object to a php script using the following JS code.\[code\] $.ajax({ url: '/somewebsite/poll/create?json=show', type: 'POST', // dataType: 'json', data: poll_data, contentType: 'application/json; charset=utf-8', success: function(data) { alert(data); } });\[/code\]My PHP code is very simple.\[code\] echo json_encode($_POST); exit;\[/code\]When I run the script and click the button that triggers the submission of the data, I receive the alert (so the actual ajax code works), but the result from my PHP script is just an empty array. I think that this is an issue with the way the object is constructed, but I am not sure, and have not been able to find a work around.Thanks in advance.
 
Back
Top