In the code snippet below, an AJAX post request is made. The function widgets_positions() is responsible for gathering information about widgets positions on a webpage and sending it via AJAX. However, there seems to be a problem with how the 'widgets' variable is being handled.
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;
}
Interestingly, when 'widgets' is replaced with a hardcoded string like 'sumo', the post request works perfectly fine, suggesting that the issue lies within the 'widgets' variable itself.
Furthermore, after adding an echo command in the code before the makePOSTRequest
call, strange behavior is observed where the value of 'widgets' gets printed out as c[1]c[1]blahblah
on the client side.
This raises the question: why does the var random = 'sumo'
get successfully sent while the contents of the 'widgets' variable do not?