FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Ajax Inbox

 


DanielXP
This code is my ajax in the page

Code:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <script type="text/javascript">
var xmlHttp
function GetXmlHttpObject(){
var objXMLHttp=null
if (window.XMLHttpRequest){
objXMLHttp=new XMLHttpRequest()
}else if (window.ActiveXObject){
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
function GetPMs(){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
alert ("Browser does not support HTTP Request")
return
}
var url="numberpms.php"
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
document.getElementById("numberpms").innerHTML = xmlHttp.responseText;
}
}
};
xmlHttp.send(null);
}
GetPMs();
setInterval("GetPMs()",1000);
</script>


And this is what displays it

Code:
<a id="numberpms"></a>


But it don't display it, it says this

Line: 35
Char: 1
Error: Uknown runtime error
Code: 0



I know nothing about Ajax or java sorry
Aredon
Looks fine to me except that I think you are calling the GetPMs() function too early. Try it onload:

Code:

onload=function(){
GetPMs();
setInterval("GetPMs()",1000);
}


In case you are testing this locally, you might want to change:
Code:

if (xmlHttp.status == 200)

to
Code:

if (xmlHttp.status == 200 || xmlHttp.status == 0)


Last thing I can think of is that your browser MIGHT still be using a cached version of the page -- one with errors on it.
DanielXP
Got it to work hes me code

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
var xmlHttp
function GetXmlHttpObject(){
var objXMLHttp=null
if (window.XMLHttpRequest){
objXMLHttp=new XMLHttpRequest()
}else if (window.ActiveXObject){
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
function GetALERTS(){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
alert ("Browser does not support HTTP Request")
return
}
var url="alerts.php"
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200 || xmlHttp.status == 0) {
document.getElementById("alerts").innerHTML = xmlHttp.responseText;
}
}
};
xmlHttp.send(null);
}

GetALERTS();
setInterval("GetALERTS()",1000);

</script>
</head>
<body bgcolor='#BCD2EE'>
<?php include("config.php"); ?>
<div id="alerts" width='100%' height='100%'></div>
</body>
</html>


Then the alerts.php is this

Code:
<?php
header("Expires: Sat, 05 Nov 2005 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
include("config.php");


...................................


Thanks for your help Aredon
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.