Προς το περιεχόμενο

AJAX


Προτεινόμενες αναρτήσεις

Δημοσ. (επεξεργασμένο)

Εχω δημιουργησει ενα αρχειο xml με περασμενα στοιχεια υποτιθεμενων φοιτητων

 

<?xml version="1.0" endoding="UTF-8"?>
<data>
<user>
<name>Stavroula </name>
<lastname>Mpoti</lastname>
<address>Swkratous 56</address>
<email>[email protected]</email>
<phonenumber>6958321920</phonenumber>
</user>

<user>
<name>Gianna </name>
<lastname>Antwniadou</lastname>
<address>Esperidwn 20</address>
<email>[email protected]</email>
<phonenumber>6925163879</phonenumber>
</user>
 

 

και θελω να εμφανισω τις διευθυνσεις ΜΟΝΟ, έγραψα τον κωδικα με βάση το παραδειγμα της σχολης. 

Ασυγχρονη επικοινωνια με on click event.

Περα απ'το οτι δεν μου εμφανιζει τα αποτελεσματα, δεν καταλαβαινω που ακριβως κολλαει το div1

Πραγαματικα δεν εχω την παραμικρη ιδεα που μπορει να ειναι το λαθος

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title> Stoixeia</title>
<script>
function loadxml()
{
var req;
if (window.XMLHttpRequest)
{
req=new XMLHttpRequest();
}
else
{
req=new ActiveXObjective("Microsoft.XMLHTTP");
}
req.onreadystatechange=function()
{
if (req.readyState==4 && req.status==200)
{
xmlDoc=req.responseXML;
txt="";
x=xmlDoc.getElementsByTagName("address");
for (i=0;i<x.length;i++)
{
txt=txt + x.childNodes[0].nodeValue+"<br>";
document.getElementById("div1").innerHTML=txt;
}
}
req.open("GET","stoixeia.xml",true);
req.send();
}
</script>
</head>
<body style="background-color:pink;">
<div id="div1"><h1>Oi Dieuthunseis twn foititwn</h1></div>
<button type="button"onclick="loadxml()">Patiste gia na emfanistoun oi dieuthunseis twn foititwn</button><br>
</body>
</html>

 

Επεξ/σία από Kyrki
Δημοσ. (επεξεργασμένο)
<!doctype html>
<html>   
	<head>    
		<meta charset="utf-8"> 
		<title>Read and parse XML</title>
		<script>
		function loadxml(){
			var req = new XMLHttpRequest();
			
			if (req){
				req.onreadystatechange=function(){
					console.log(req.readyState+':'+req.status);
					
					if (req.readyState==4){
						if (req.status!=200){
							document.getElementById("div1").innerHTML = 'XML Request Failed';
						}else{
							var xmlDoc = this.responseXML;
							console.log(xmlDoc);
							var i, x = xmlDoc.getElementsByTagName("address");
							
							for (i=0;i<x.length;i++){
								//ERROR txt=txt + x.childNodes[0].nodeValue+"<br>";
								//x is an array of tag elements the i'th elem is x[i]
								// and from that you take the value of the 0yh child node
								//which in this case is the address string
								document.getElementById("div1").innerHTML+= 
                                  	x[i].childNodes[0].nodeValue+"<br>";
							}						
						}
					}
				}
				
				req.open("GET", "stoixeia.xml", true);
				req.send();
			}else{
				document.getElementById("div1").innerHTML = 'No AJAX Support';
			}
		}
		</script>
	</head>
	<body>
		<h1>Oi Dieuthunseis twn foititwn</h1>
		<div id="div1"></div>
		<br>&nbsp;<br>
		<button type="button"onclick="loadxml()">
          	Patiste gia na emfanistoun oi dieuthunseis twn foititwn
      	</button>
	</body>
</html>

πάνε εδώ > http://104.236.83.163/xmltest.html  για να το δεις εν δράση.

Επεξ/σία από ajaxmonkey4hire
Δημοσ.
23 ώρες πριν, ajaxmonkey4hire είπε

<!doctype html>
<html>   
	<head>    
		<meta charset="utf-8"> 
		<title>Read and parse XML</title>
		<script>
		function loadxml(){
			var req = new XMLHttpRequest();
			
			if (req){
				req.onreadystatechange=function(){
					console.log(req.readyState+':'+req.status);
					
					if (req.readyState==4){
						if (req.status!=200){
							document.getElementById("div1").innerHTML = 'XML Request Failed';
						}else{
							var xmlDoc = this.responseXML;
							console.log(xmlDoc);
							var i, x = xmlDoc.getElementsByTagName("address");
							
							for (i=0;i<x.length;i++){
								//ERROR txt=txt + x.childNodes[0].nodeValue+"<br>";
								//x is an array of tag elements the i'th elem is x[i]
								// and from that you take the value of the 0yh child node
								//which in this case is the address string
								document.getElementById("div1").innerHTML+= 
                                  	x[i].childNodes[0].nodeValue+"<br>";
							}						
						}
					}
				}
				
				req.open("GET", "stoixeia.xml", true);
				req.send();
			}else{
				document.getElementById("div1").innerHTML = 'No AJAX Support';
			}
		}
		</script>
	</head>
	<body>
		<h1>Oi Dieuthunseis twn foititwn</h1>
		<div id="div1"></div>
		<br>&nbsp;<br>
		<button type="button"onclick="loadxml()">
          	Patiste gia na emfanistoun oi dieuthunseis twn foititwn
      	</button>
	</body>
</html>

πάνε εδώ > http://104.236.83.163/xmltest.html  για να το δεις εν δράση.

ε σε ευχαριστω παρα πολυ αλλα τελικα και ο δικος μου κωδικας ειναι πληρως λειτουργικος απλα δεν ειχα εγκαταστησει το xampp οποτε λογικο να μην ανοιγει.!

Δεν ειμαι τοσο  χαζη οσο δειχνω!απλα δεν ηξερα και δεν ειχα δει το e mail του καθηγητη γοι ατη σχετικη εφαρμογη.

THNKS AGAIN!

Δημοσ. (επεξεργασμένο)

ο κώδικας που έβαλες στην ανάρτηση περιέχει ένα λάθος και δεν μπορεί να είναι λειτουργικός. Γράφεις:

txt=txt + x.childNodes[0].nodeValue

Αυτό δεν μπορεί να λειτουργήσει διότι το x είναι Array.

 

Επεξ/σία από ajaxmonkey4hire

Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε

Πρέπει να είστε μέλος για να αφήσετε σχόλιο

Δημιουργία λογαριασμού

Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!

Δημιουργία νέου λογαριασμού

Σύνδεση

Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.

Συνδεθείτε τώρα
  • Δημιουργία νέου...