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