php - AJAX: how to post empty arrays? -


i have associative array lists. take @ following json:

console.log(json.stringify(fields); 

output

{   "sb1":[],   "sb2":["val1","val2","val3"],   "sb3":["val1","val2","val3"] } 

as can see, array-entry "sb1" empty. array "sb1" disappear while posting var "fields" php.

here code-snippet:

$(document).ready(function() {   $("#button").click(function(e) {     e.preventdefault();     var fields = {}; //the following saves selectboxes , options in var fields//     $("select").each(function() {       var $select = $(this);       fields[$select.attr('name')] = $select.find('option').map(function() {         return $(this).val();       }).get();     });      var jsonobj = fields;     var jsonstringify = json.stringify(fields);     console.log("json.stringify(fields): " + jsonstringify); //result ok      $.ajax({       url: "savejson.php",       type: "post",       data: { jsonstringify : jsonstringify },       success: function (response) {         console.log("data transmitted: " + response); //response doesnt transmit empty arrays!       },       error: function(jqxhr, textstatus, errorthrown) {         console.log(textstatus, errorthrown);       }     });   }); }); 

your javascript code send empty array. if want have empty array in response of request, have modify code of server.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -