Ciao a tutti.
Avrei bisogno del vostro aiuto per capire il funzionamento di questa funzione che ho trovato in uso su un sito web, e che non riesco a decifrare:
qualcuno sa aiutarmi?codice:var obj; function addFav(itm, id) { obj = false; if(navigator.userAgent.indexOf('Opera') != -1 || navigator.userAgent.indexOf('Konqueror') != -1) { return true; } if(window.XMLHttpRequest) { try { obj = new XMLHttpRequest(); } catch(e) { obj = false; } } else if(window.ActiveXObject) { try { obj = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { obj = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { return true; } } } if(obj) { var prevNum = itm.innerHTML.match(/\((.+)\)/); var prevStr = itm.innerHTML; itm.innerHTML = 'Please wait...'; obj.onreadystatechange = function() { getChange(itm, prevNum, prevStr); }; obj.open("GET", 'favlive.php?id=' + id, true); obj.send(0); return false; } else { return true; } } function getChange(itm, prevNum, prevStr) { if (obj.readyState == 4) { if (obj.status == 200) { if(obj.responseText.indexOf('true') != -1) { alert('Thanks, your vote has been registered!'); itm.innerHTML = 'Favourites (' + (parseInt(prevNum[1]) + 1) + ')'; } else { alert('You\'ve already voted for this item!'); itm.innerHTML = prevStr; } } else { itm.innerHTML = prevStr; } } }
si tratta per caso di ajax? se si come funziona?
la funzione viene sfruttata in questo sito:
http://thesis.veracon.net/
per incrementare dei voti.
Mi aiutate?

Rispondi quotando