AJAX - The Complete Reference

(avery) #1

Chapter 2: Pre-Ajax JavaScript Communications Techniques 27


PART I


else
var iframe = document.createElement("iframe");
iframe.style.visibility = "hidden";
document.body.appendChild(iframe);
return iframe;
}

function makeIframeForm(ifr, url, payload)
{
var ifrDoc = null;
var ifrWindow = ifr.contentWindow || ifr.contentDocument;
if (ifrWindow.document)
ifrDoc = ifrWindow.document;
else
ifrDoc = ifrWindow;

if (!ifrDoc.body)
{
var html = ifrDoc.createElement("HTML");
ifrDoc.appendChild(html);
var head = ifrDoc.createElement("HEAD");
html.appendChild(head);

var body = ifrDoc.createElement("BODY");
html.appendChild(body);
}
var ifrForm = ifrDoc.createElement("FORM");
ifrForm.action = url;
ifrForm.method = "post";
ifrDoc.body.appendChild(ifrForm);
for (var key in payload)
{
var ifrText = ifrDoc.createElement("INPUT");
ifrText.type = "text";
ifrText.name = key;
ifrText.value = encodeValue(payload[key]);
ifrForm.appendChild(ifrText);
}
return ifrForm;
}
var ifr = makeIframe();
var ifrForm = makeIframeForm(ifr, url, payload);
ifrForm.submit();
}

function rate(rating, comment)
{
var ratingVal = 0;
/* determine rating value */
for (var i=0; i < rating.length; i++)
{
if (rating[i].checked)
{
ratingVal = rating[i].value;
Free download pdf