PDA

View Full Version : Site Alert



Dentafrice1
06-01-2007, 02:54 PM
Ok I have my site alert script that pops up.

It used to be just a JS alert that was refreshed in an iframe and it popped up.

But I made one like on Habbo. How can I use ajax to get the alerts?

+REP to anyone who helps me complete this and rares on habbo

Kevin

Ceoxe
06-01-2007, 02:59 PM
I think its somehting like this, correct me if not:


<a href="javascript:void(null)"
onclick="alert('Class was cancelled this day.')">
<font size="2" face="verdana" color="#c51585">
<b>- 31 Oct 05 -</b></font></a>Link for tutorial: http://www.activewidgets.com/javascript.forum.8395.4/java-alert-boxes.html

Lµke
06-01-2007, 03:00 PM
Don't know if this is what you want but, i typed in "Ajax alerts" on google and this popped up;


http://www.servletsuite.com/servlets/ajaxalerttag.htm

Dentafrice1
06-01-2007, 03:02 PM
Neither one of those are what im looking for but +rep to you both in two days.

Tomm
06-01-2007, 03:03 PM
Don't know if this is what you want but, i typed in "Ajax alerts" on google and this popped up;


http://www.servletsuite.com/servlets/ajaxalerttag.htm

Yes but unless he is running a server that supports java servlet pages then that it totally useless crap.

Dentafrice1
06-01-2007, 03:23 PM
Can you look tom for something?

Ceoxe
06-01-2007, 05:48 PM
i found this, its not AJAx but im not sure


<tr>
<td width='100&#37;' onMousedown='initializedragie()'>
<table border='0' width='100%' cellspacing='0' cellpadding='0'>
<tr>
<td width='1%' background='bg image'><img src='/images/layout/alert/sign_lt.gif' width='15' height='97' border='0'></td>
<td width='100%' bgcolor='#EFEFEF'> <font size='1' face='Verdana' color='#000000'><font face='Verdana' size='1' color='#000000'><center>Text Here<!-- line --><br><!-- break --></font></font><br>

<a href='#' onClick='hidebox();return false'><center><br><img src='the okey image' width='38' height='23' border='0'></a></center>
<td width='1%' background='image'><img src='alert image' width='16' height='97' border='0'></td>
</tr>
</table>
</td>
</tr>

Mentor
06-01-2007, 06:13 PM
Ok I have my site alert script that pops up.

It used to be just a JS alert that was refreshed in an iframe and it popped up.

But I made one like on Habbo. How can I use ajax to get the alerts?

+REP to anyone who helps me complete this and rares on habbo

Kevin
Depends what you want ajax for?

SO you have a habbo style alert box?

You use ajax, much in the same way as you would use the iframe. You have a php page, you make ajax check it every say 20 seconds or what ever. If it has a message on it, then ajax returns it, and u call the function to make the pop up. If not, theres no alert, so ajax doesnt call the alert function.

The php page changes depedning on whether or not theres an alert or not.

Dentafrice1
06-01-2007, 07:13 PM
http://www.habbo-record.com/site/index.php

is the site the code will be on to display the alert. I have the code to display the alert. I just need to get the alert if there is one.

I could do this VIA php but i cant using ajax

Ceoxe
06-01-2007, 07:50 PM
I dont quite understand what thta last post meant

nets
06-01-2007, 08:41 PM
Set an interval which makes a AJAX request to the PHP page, output nothing to the PHP page if you don't want anything displayed. Have JavaScript check the response with an if statement, and if it isn't null alert the reponse.

Dentafrice1
06-01-2007, 08:58 PM
Thats the problem nets.. I have no clue about JS . Never studied it thats why im trying to do this.

I only know advanced PHP.

Mentor
06-01-2007, 10:45 PM
Most people have havent studied any web programming langages? if youve ever used VB, ASP etc its actualy very simlar syntax, although less like Vb and more like php in other ways "/

it formats alot like php, aka the
bla{
somthing;
somthing;
}

but the varibles are refranced more like vb. Useing the Document Object modle

thisobject.thisproperty.thissubproperty

(sorry for use of persudo code, im lazy)

Anyway, heres a nice 30 second ajax tutoral, to give you the low down on that
http://rajshekhar.net/blog/archives/85-Rasmus-30-second-AJAX-Tutorial.html

and how to call a function at set intervals use setTimeout

t=1
function timedCount()
{
t++ ;
if (t < 5 ) {
t=setTimeout("timedCount()",4000) ;
}
}

timedCount()

Dentafrice1
06-01-2007, 11:18 PM
var intervalID;

function show()
{
intervalID = setInterval(showHint, 1000);
}


var xmlHttp
function showHint()
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="cfh.php"
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}

function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}

I have that to pull the PHP page out. Would that be correct?

Mentor
06-01-2007, 11:21 PM
u need to call the show function in the show hint function, or at least call the interval from that, or it will only check the first time its run, rather than keep checking

Dentafrice1
06-01-2007, 11:25 PM
var xmlHttp
function showHint()
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="clienthint2.php"
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

var intervalID;

function show()
{
intervalID = setInterval(showHint, 1000);
}

}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}

function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}



This?

Want to hide these adverts? Register an account for free!