vec neko vrijeme radim na nekoj scripti temeljenoj na ajaxu (javascript+php+mysql DB) i vec sam pri kraju.
Naime, imam problem sa back/forward akcijama. Citao sam po forumima da su to rijesili ali za neke frameworke. Posto ja ne koristim nikakav framework moze li mi neko pojasniti kako to napraviti na najkraci/najbolji nacin.
Evo funkcija preko koje ucitavam linkove, napomena pored httprequesta koristim i obicno linkanje.
Code:
function getxmlhttp(){
var xmlhttp=false;
try {
xmlhttp= new ActiveXObject("Msxml2.XMLHTTP");
} catch(e){
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
xmlhttp= false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined'){
xmlhttp= new XMLHttpRequest();
}
return xmlhttp;
};
.
.
.
function processajax(obj,serverPage){
var theimg;
var lok="<div class=\"poruka\"><img src=\"slike/indikator.gif\" width=\"70\" height=\"10\" /><br>Ucitava se...........</div>";
var xmlhttp=getxmlhttp();
xmlhttp.open("GET",serverPage+"&ssid="+Math.random(),true);
document.getElementById(obj).innerHTML=lok;
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && (xmlhttp.status==200 || xmlhttp.status == 304)){
document.getElementById(obj).innerHTML=xmlhttp.responseText;
//alert(xmlhttp.responsetext);
}
}
xmlhttp.send(null);
};
function idi(id){
var lokacija= "akcija.php?sta=lokacija&idd="+id;
//alert(id);
processajax("tijelo",lokacija);
};
.
.
.
LINK:
<a href="javascript:idi(3)" >Link</a>
function getxmlhttp(){
var xmlhttp=false;
try {
xmlhttp= new ActiveXObject("Msxml2.XMLHTTP");
} catch(e){
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
xmlhttp= false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined'){
xmlhttp= new XMLHttpRequest();
}
return xmlhttp;
};
.
.
.
function processajax(obj,serverPage){
var theimg;
var lok="<div class=\"poruka\"><img src=\"slike/indikator.gif\" width=\"70\" height=\"10\" /><br>Ucitava se...........</div>";
var xmlhttp=getxmlhttp();
xmlhttp.open("GET",serverPage+"&ssid="+Math.random(),true);
document.getElementById(obj).innerHTML=lok;
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && (xmlhttp.status==200 || xmlhttp.status == 304)){
document.getElementById(obj).innerHTML=xmlhttp.responseText;
//alert(xmlhttp.responsetext);
}
}
xmlhttp.send(null);
};
function idi(id){
var lokacija= "akcija.php?sta=lokacija&idd="+id;
//alert(id);
processajax("tijelo",lokacija);
};
.
.
.
LINK:
<a href="javascript:idi(3)" >Link</a>
Give me six hours to chop down a tree and I will spend the first four sharpening the axe.