1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| function addremove(favid){
// Configure those variables as appropriate
var divid = 'status';
var url = 'addremove.php';
// The XMLHttpRequest object
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Your browser does not support AJAX.");
return false;
}
}
}
// Generate timestamp for preventing IE caching the GET request
fetch_unix_timestamp = function()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}
var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;
// This code sends the variables through AJAX and gets the response
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState!=4){
document.getElementById(divid).innerHTML='<img src="spinner.gif">';
}
if(xmlHttp.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("GET",nocacheurl+"&favid="+favid,true);
xmlHttp.send(null);
// Finally, some code for button toggle
var button = document.getElementById('button');
switch(button.name)
{
case 'button0':
button.src = 'add.png';
button.name = 'button1';
break;
case 'button1':
button.src = '/delete.png';
button.name = 'button0';
break;
}
} |
Partager