Poslao: 13 Dec 2008 11:46
|
offline
- lnenad
- Stručni saradnik
Web
- Pridružio: 16 Jan 2007
- Poruke: 2860
- Gde živiš: Bijeljina
|
Ovako, treba da pozovem neku php stranicu i da ispise nesto (primjer) i to radi kako treba, ali posto imam vise stvari, zelim da napravim vise rezultatnih divova, rez1, rez2, rez3 itd..
E sad, greska je u tome sto nisam toliko strucan sa jsom pa mi treba pomoc
Evo sta sam ja "napravio"
function dc(id)
{
var idd = "rez"+id;
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url = "dc.php?id="+id;
xmlHttp.onreadystatechange=stateChanged(id)
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(idd)
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById(idd).innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
Naravno stranica se preko PHP lepo generise. Sta nisam dobro uradio ?
|
|
|
Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
|
|
Poslao: 13 Dec 2008 15:51
|
offline
- Blood
- Ugledni građanin
- Pridružio: 26 Jul 2003
- Poruke: 384
- Gde živiš: Beograd
|
Nisam bas siguran sta tacno zelis, ali ako zelis da ti se taj isti rezultat ispise na vise razlicitih mesta, uradi sledece:
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById(idd).innerHTML=xmlHttp.responseText;
document.getElementById('rez1').innerHTML=xmlHttp.responseText;
document.getElementById('rez2').innerHTML=xmlHttp.responseText;
document.getElementById('rez3').innerHTML=xmlHttp.responseText;
// ...
}
}
|
|
|
|
Poslao: 13 Dec 2008 15:52
|
offline
- lnenad
- Stručni saradnik
Web
- Pridružio: 16 Jan 2007
- Poruke: 2860
- Gde živiš: Bijeljina
|
Nisam dobro objasnio, broj rezultata nije fiksan. Mjenja se konstantno.
Uglavnom treba da prodje variabla idd do one funkcije koja mjenja sadrzaj diva, sto ne prolazi
Citat:function stateChanged(idd)
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById(idd).innerHTML=xmlHttp.responseText
}
}
|
|
|
|
Poslao: 13 Dec 2008 20:32
|
offline
- igor86
- Stručni saradnik
Web programiranje
- Pridružio: 24 Maj 2006
- Poruke: 1633
|
Valjda odgovaras sa PHP-om kroz XML, znaci navodi u samom XML-u koji div ti se traba refreshovati i sa kojim textom.
recimo
<content>
<id>tvoj_div_id</id>
<html>tvoj_content</html>
</content>
<content>
<id>tvoj_div_id2</id>
<html>tvoj_content2</html>
</content>
i onda u JS-u
for(x in xmlHttp.response.content)
$(xmlHttp.response.content[x].id).innerHTML = xmlHttp.response.content[x].html;
mislim da ce s razumjeti.
Inace ovo gore si lose zamislio, onreadystatechange funkcija ce biti pozvana i argument ce joj biti proslijedjen rezultat response-a
|
|
|
|
|
Poslao: 13 Dec 2008 23:28
|
offline
- igor86
- Stručni saradnik
Web programiranje
- Pridružio: 24 Maj 2006
- Poruke: 1633
|
evo pazi na sta sam mislio
function dc(){
xmlHttp=GetXmlHttpObject();
xmlHttp.onreadystatechange=function(){if(xmlHttp.readyState==4){ stateChanged( xmlHttp.responseXML );}};
xmlHttp.open("GET",'rez.xml',true)
xmlHttp.send(null)
}
function stateChanged(Response){
var XmlObj = Response.getElementsByTagName('content');
for (i=0;i<XmlObj.length;i++){
var id = XmlObj[i].childNodes[1].firstChild.nodeValue;
var html = XmlObj[i].childNodes[3].firstChild.nodeValue;
document.getElementById(id).innerHTML = html;
}
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{xmlHttp=new XMLHttpRequest();}
catch(e){try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}}
return xmlHttp;
}
<div id="tvoj_div_id">tvoj_div_id start content</div>
<div id="tvoj_div_id2">tvoj_div_id2 start content</div>
<br/>
<a href='#' onclick="dc();return false;">Click</a>
rez.xml
<contents>
<content>
<id>tvoj_div_id</id>
<html>tvoj_div_id end content</html>
</content>
<content>
<id>tvoj_div_id2</id>
<html>tvoj_div_id2 end content</html>
</content>
</contents>
|
|
|
|
|
Poslao: 15 Dec 2008 13:31
|
offline
- igor86
- Stručni saradnik
Web programiranje
- Pridružio: 24 Maj 2006
- Poruke: 1633
|
moras da u php-u stavis prije generisaja rezultata
header("Content-type: text/xml");
Dopuna: 15 Dec 2008 13:31
evo nesto me ovo malo zainteresvalo pa sam napravio neko bolje rjesenje.
Recimo da kroz xml koji dobijes mozes da mjenjas sve property-e odredjenog objecta.
Okacio sam primjer.
https://www.mycity.rs/must-login.png
|
|
|
|
Poslao: 15 Dec 2008 14:39
|
offline
- lnenad
- Stručni saradnik
Web
- Pridružio: 16 Jan 2007
- Poruke: 2860
- Gde živiš: Bijeljina
|
Meni u onoj arhivi nema javascripta nikako ?
|
|
|
|
|