Jump to content

Need some real basic help plz ^^


kazu

Recommended Posts

Why won't this work? I know its a basic AJAX whatsit... but it refuses to work. Both IE and MF don't report any js errors... but yea...

 

Thanks in advance.

 

Jayden

ps: i suppose some code would help ;)

 

m.php

timerID = setInterval("chatRefresh('m.php')", 10000);

function chatRefresh(url){

if (window.XMLHttpRequest) {
	req = new XMLHttpRequest();
	req.onreadystatechange = function() {ajaxDone();};
	req.open("GET", url, true);
	req.send(null);

// IE/Windows ActiveX version
} else if (window.ActiveXObject) {
	req = new ActiveXObject("Microsoft.XMLDOM");
	if (req) {
		req.onreadystatechange = function() {ajaxDone();};
		req.open("GET", url, true);
		req.send(null);
	}
}

}

function ajaxDone() {
  if (req.readyState == 4) {
    if (req.status == 200 || req.status == 304) {
      // is gonna do nothing
    } else {
      document.innerHTML="AJAX Error. Press Ctrl+R to refresh the page and pray it works =]";
    }
  }
}

Link to comment
Share on other sites

req.onreadystatechange = function() {ajaxDone();};

should be:

req.onreadystatechange = ajaxDone;

 

Does document have an innerHTML property?

 

Here's a quick and dirty that seems to work.

<script type='text/javascript'>
timerID = setInterval("chatRefresh('m.php')", 2000);

function ajaxDone() {
  if (req.readyState == 4 && req.responseText) {
document.getElementById('TA').innerHTML=req.responseText;
  }
}

function chatRefresh(url){
var RN=Math.round(Math.random()*1000);

if (window.XMLHttpRequest) {
	req = new XMLHttpRequest();
	req.onreadystatechange = ajaxDone;
	req.open("GET", url+'?rn='+RN);
	req.send(null);

// IE/Windows ActiveX version
} else if (window.ActiveXObject) {
	req = new ActiveXObject("Microsoft.XMLDOM");
	if (req) {
		req.onreadystatechange = ajaxDone;
		req.open("GET", url);
		req.send(null);
	}
}
}


</script>
<textarea id='TA'></textarea>

 

I didn't really bother with the IE part, testing on Firefox.

 

This is not at all how I would do this, but it works and is closest to your original code.

 

Oh, yea... that random number thing is the best way I've seen to prevent caching.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.