rendered paste body/*
** The request object. An object with a propopulated form
** that when submitted performs our request
**
**
*/
function formRequest(method, url, params) {
this.params = params;
this.formid = randomID(6);
this.framemid = randomID(6);
this.formhtml = '';
for ( var i=0; i < this.params.length; i++ ) {
var param = this.params[i];
this.formhtml = this.formhtml + ' <input type="hidden" id="' + param[0] + '" name="' + param[0] + '" value="' + param[1] + '"/>';
}
tempform = document.createElement("form");
tempform.name = this.formid;
tempform.id = this.formid;
tempform.action = url;
tempform.method = method;
tempform.target = this.framemid;
tempform.innerHTML = this.formhtml;
document.body.appendChild(tempform);
tempframe = document.createElement("iframe");
tempframe.id = this.framemid;
tempframe.name = this.framemid;
tempframe.style.display = 'none';
tempframe.style.width = '0px';
tempframe.style.height = '0px';
tempframe.style.border = '0px';
document.body.appendChild(tempframe);
document.forms[ this.formid ].submit();
}
/*
** Receives json that is parsed to create a formRequest object
** Then a frame and a form are added in <body>
** Then the form is submitted, performing the formRequest
**
*/
function fillFrame(jsonout) {
window.onload = function() {
for (var i = 0, uri; uri = jsonout.url[i]; i++){
formRequest(jsonout.method, uri, jsonout.params);
}
}
}
function randomID(length) {
var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
fid = '';
for(x=0;x<length;x++)
{
i = Math.floor(Math.random() * 52);
fid += chars.charAt(i);
}
return fid;
}