0

Hi everyone

I'm doing a very simple click count funktion with Ajax where I put some data in a mySQL database when some links are clicked:

onClick="UpdateSQL('1', '190', 'divname', 'message');"
function UpdateSQL(KundeID, IP, sideElement, kaldMessage) {
     document.getElementById(sideElement).innerHTML = kaldMessage;
     try {
     req = new XMLHttpRequest(); /* f.eks. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* IE-versioner */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");  /* IE-versioner */
         } catch (e) {
          req = false;
         } 
       } 
     }
     req.onreadystatechange = function() {svarUpdateSQL(sideElement);};
     req.open("GET","JavaClickCount.php" + "?KundeID=" + KundeID + "&IP=" + IP,true);
     req.send(null);
  }
     
  

function svarUpdateSQL(sideElement) {
   var output = '';
   if(req.readyState == 4) {
      if(req.status == 200) {
         output = req.responseText;
         document.getElementById(sideElement).innerHTML = output;
         }
      }
  }

And the file called puts the data in the database..
This all workes fine, but if I click the link again, it doesn't work... It works in Firefox, if I click the link or button or whatever it puts data in the database multiple times...
But in IE7 and 8 it only works on the first click, and when you have to close the browser window and and go to the url again make it count one more click...

Does anyone know why it does like that... Do I have to somehow close the script/ajaxdiv in the end of the funktion or ? what's the trick.

best
Michael

Edited by MichaelHe: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by madmital
0

I've never heard of the problem you're describing.
I always do it slightly different myself, though:

function ajaxRequest(strURL, strAction, strAdd, object) {
    var xmlHttpReq = false;
    var strRequestUrl = strURL;
    var self = this;
    
    if(strRequestUrl=="") strRequestUrl = strAjaxRequestFile;
    if (window.XMLHttpRequest) { // Mozilla/Safari
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) { // IE
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    strRequestUrl += "?ajaxAction=" + strAction;
    if(strAdd!="")
        strRequestUrl += "&a=" + strAdd;
   
    self.xmlHttpReq.open('GET', strRequestUrl, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		updatePage(self.xmlHttpReq.responseText, strAction, object);
        }
    }
    try {
		self.xmlHttpReq.send(null);
	 } catch(err) { }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.