Howdy, erme2.
Joining the elements of the array with "&" is a requirement for HTTP communication. The string returned by aParams.join() is the request body sent to the server, and "&" has to separate the key/value pairs. No other character can be used.
You do have a point that problems can arise if "&" is in an element of the array. However, the code in Chapter 2 makes this a non-issue by encoding both the key and the value with the encodeURIComponent() method. Here is the getRequestBody() function as detailed in Chapter 2:
Code:
function getRequestBody(oForm) {
var aParams = new Array();
for (var i=0 ; i < oForm.elements.length; i++) {
var sParam = encodeURIComponent(oForm.elements[i].name);
sParam += "=";
sParam += encodeURIComponent(oForm.elements[i].value);
aParams.push(sParam);
}
return aParams.join("&");
}
Any "&" that is passed to encodeURIComponent() ends up as %26, effectively dodging any issue that would otherwise arise with "&".
------------------------
Jeremy McPeak
Author of:
Professional Ajax, 2nd Edition
Beginning JavaScript, 3rd Edition
http://www.wdonline.com