Ajax simple example problem

A

Alex

Example uploaded to:
http://www.clickatus.com/ajax/

BTW - This is for FIREFOX, won't work in IE.

I don't know why but when it is executed the browser still in loading
state... Even though XMLHttpRequest already got its string from the
server...

Any help?

PHP server script outputs "Hello"


<html><head><meta http-equiv="Content-Type" content="text/html;
charset=windows-1252"><title>Ajax Test</title>

<script language="javascript" type="text/javascript">

//Run my function "f_StartEngine" on page load
window.onload=f_StartEngine;

//Starts up engine
function f_StartEngine(){

//netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
var ajax = new XMLHttpRequest();
ajax.open('POST', "ajax_test.php", true);
ajax.onreadystatechange = function () {
if (ajax.readyState == 4) {
if (ajax.status == 200) document.write(eval(
'('+ajax.responseText+')' ));
else alert("An error occurred: " + ajax.statusText);
}
};
ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
ajax.send(null);
}

</script></head><body></body></html>
 
M

Martin Honnen

Alex wrote:

I don't know why but when it is executed the browser still in loading
state...
ajax.onreadystatechange = function () {
if (ajax.readyState == 4) {
if (ajax.status == 200) document.write(eval(
'('+ajax.responseText+')' ));

Well that has nothing to do with that new toy "Ajax" but rather with
your use of document.write after the document has been loaded. That does
an implicit document.open() and after your document.write() call waits
for further document.write() calls or for a document.close().
Not sure why you think you neec document.write but calling
document.close() after that will stop Mozilla from showing the loading
state.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top