Wait for IFrame without a callback function?

W

whadar

Hello all,
I need a replacement for xmlhttprequest activex cause I'm running
clients with no activex support.
The request should be POST and synchronous.

There are few implementations for xmlhttprequest out there, but from
what I saw they use GET and asynchronous events.

I am dynamically creating a form and submitting it to a hidden iframe.
The iframe is still in its "loading" state so i need to wait for it.
the problem is I cant use the onreadystate event cause I need the
function itself to return the response. So I tried setTimeout - Here's
the code:

var response = "";
function CallServer(xml, url) {
//remove previous form
if (document.forms.length > 0)
{
document.forms[0].removeNode(true);
response = ""
}
var formObj = document.createElement ("form");
formObj.innerHTML = "<input id=\"xmlRequest\" name=\"xmlRequest\"
type=\"text\" value=\"" + xml + "\" />";
window.document.appendChild(formObj)

formObj.action = url;
formObj.method = "post";
formObj.target = "ifrmSendData";
formObj.submit();

WaitForResponse();

return response;
}

function WaitForResponse()
{
if (ifrmSendData.frameElement.readyState == "complete")
{
response = ifrmSendData.document.body.innerText;
}
else
{
setTimeout("WaitForResponse()", 100);
}
}

Because setTimeout works asynchronously WaitForResponse does not
"wait", and simply return the default empty string...

Another thing i tried to do is a while loop that waits for readyState
== "complete" but that hangs the browser and the iframe is never
loaded.

How can I wait for the iframe to be loaded and then read the response?

If not possible, other alternatives for synchronous xmlhttprequest are
most welcome...

Thanks very much,
Hadar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top