AJAX - The Complete Reference

(avery) #1

PART II


Chapter 9: Site and Application Architecture with Ajax 423


html.appendChild(head);
var body = ifrDoc.createElement("BODY");
html.appendChild(body);
}
/* create form to submit */
var ifrForm = ifrDoc.createElement("FORM");
ifrForm.action = url;
ifrForm.method = "post";
ifrDoc.body.appendChild(ifrForm);

/* create text fields for each name-value pair */
var keys = payload.split("&");
for (var i=0;i<keys.length;i++)
{
var nv = keys[i].split("=");
var ifrText = ifrDoc.createElement("INPUT");
ifrText.type = "text";
ifrText.name = nv[0];
ifrText.value = nv[1];
ifrForm.appendChild(ifrText);
}
if (request.transportIndicator)
{
/* add in text field indicating transport type */
var ifrText = ifrDoc.createElement("INPUT");
ifrText.type = "text";
ifrText.name = AjaxTCR.comm.DEFAULT_TRANSPORT_HEADER;
ifrText.value = AjaxTCR.comm.DEFAULT_IFRAME_TRANSPORT_VALUE;
ifrForm.appendChild(ifrText);
}
return ifrForm;
}
},

When the iframe comes back, the response codes are faked and responseText and
responseXML are populated. Given the way the iframe works, it is quite easy to do this
compared to other transports.

_handleIFrameResponse : function(response, iframe){
/* set status codes */
response.httpStatus = 200;
response.httpStatusText = "OK";

/* populate responseText with whatever is in the body */
if (iframe.contentWindow.document.body)
response.responseText = iframe.contentWindow.document.body.innerHTML;
/* populate responseXML in case there is XML in the response */
if (iframe.contentWindow.document.XMLDocument)
response.responseXML = iframe.contentWindow.document.XMLDocument;
else
response.responseXML = iframe.contentWindow.document;
/* handle response normally */
AjaxTCR.comm._handleResponse(response);
},
Free download pdf