The function below makes an AJAX post. makepostrequest is just a standard ajax post request function I wrote that I have omitted since it’s not the source of the problem. The function below does not send ‘widgets’.
function widgets_positions(){
var widgets = '';
var col_1 = document.getElementById('col_1');
var col_2 = document.getElementById('col_2');
var col_3 = document.getElementById('col_3');
for(i = 0; i < col_1.childNodes.length; i++) {
var str1 = col_1.childNodes[i].className;
if(str1 && str1.match('widget')) widgets+='&c[1]['+i+']='+col_1.childNodes[i].id;
}
makePOSTRequest('/ajax.php',"widgets="+widgets);
return true;
}
BUT if in place of ‘widgets’ I try to post
var random = 'sumo'
makePOSTRequest('/ajax.php',"widgets="+random);
it works.
Not only that, if I place an echo command in the above before 'makepostrequest', 'widgets' get printed out on the clinetside as c[1]c[1]blahblah.
So why does var random = 'sumo' get sent but the 'widgets' variable does not?
It’s because ‘widgets’ starts with an &, which will mark the beginning of another variable definition in that request. So ‘widgets’ goes empty.
Try to remove that ‘&’, and parse it accordingly in server-side to correctly read each widget.