i have a JS function that would send data to a server. In the function i fill a array(row_data) with data from input fields. The array is not empty and i can get values after i set them. But if i put the array to a ajax call, the array is completely empty. I dont't understand this behavior.
function send_data() {
var d = new Date();
var row_data = [];
timestamp = d.getTime();
for(i = 1; i <= rows; i++) {
row_data[i] = [];
row_data[i]['bold'] = jQuery('#bold' + i + '_val').val();
row_data[i]['italic'] = jQuery('#italic' + i + '_val').val();
row_data[i]['underline'] = jQuery('#underline' + i + '_val').val();
row_data[i]['align'] = jQuery('#align' + i + '_val').val();
row_data[i]['capitalize'] = jQuery('#capitalize' + i + '_val').val();
row_data[i]['curved'] = jQuery('#curved' + i + '_val').val();
row_data[i]['font'] = jQuery('#font' + i + '_val').val();
row_data[i]['font_size'] = jQuery('#fontsize' + i + '_val').val();
row_data[i]['abstand'] = jQuery('#abstand' + i + '_val').val();
row_data[i]['text'] = jQuery('#zeile' + i).val();
if (row_data.length <1) alert("array is empty");
}
if (row_data.length <1) alert("array is empty");
$.ajax({
method: 'POST',
url: server_script_url,
cache: false,
dataType: 'xml',
data: { 'id': session_id,
'rows' : rows,
'row_data' : row_data
}
})
.done(function( xml ) {
var image = $(xml).find('file').first().text();
jQuery('#preview_image').attr('src', image + '?t=' + timestamp);
})
.fail(function() {
alert('Leider gab es bei der Datenübermittlung einen unbekannten Fehler.');
});
}