It all works nicely though if I use mouseover events as the trigger. If I use click events then the AJAX bit breaks.
Here's the code (mostly):
Adding event listener to all links (firefox tells me errors but it works?!). When I switch from mouseover to click, the whole thing breaks down.
Expand|Select|Wrap|Line Numbers
- function listenAllLinks() {
- var a= document.getElementsByTagName("a");
- for (x in a) {
- a[x].addEventListener("mouseover",exit,true);
- }
- }
Expand|Select|Wrap|Line Numbers
- function exit() {
- xmlHttp=GetXmlHttpObject();
- if (xmlHttp==null) {
- //alert ("Browser does not support HTTP Request")
- return
- }
- var script= "exit.php";
- var exitPage= escape(this);
- var url=script+"?exit_page="+exitPage+"&sid="+Math.random();
- xmlHttp.onreadystatechange=stateChanged;
- xmlHttp.open("GET",url,true);
- xmlHttp.send(null);
- }
- }
- function stateChanged() {
- if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
- if (xmlHttp.responseText==0) {
- //alert('error');
- }
- else {
- //alert('success');
- }
- }
- }
- function GetXmlHttpObject() {
- var xmlHttp=null;
- try { // Firefox, Opera 8.0+, Safari
- xmlHttp=new XMLHttpRequest();
- }
- catch (e) { //Internet Explorer
- try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
- catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
- }
- return xmlHttp;
- }
The other oddity is that on my localhost it works but on my live site it doesn't.
Does anyone know how I can fix this or perhaps a slightly different approach?
Thanks in advance!
Henry
Using apache 2, php 5, mysql 5 (local), apache2 php 4.3 mysql4.1 (live)