|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Mar 2006
Città: Bergamo
Messaggi: 2499
|
[AJAX] problema con responseXML
forse è l'ora tarda, ma non riesco a fare il parsing della risposta xml...posto un po di codice:
ajax.js Codice:
function makeRequest(url) { var httpRequest; if (window.XMLHttpRequest) { // Mozilla, Safari, ... httpRequest = new XMLHttpRequest(); if (httpRequest.overrideMimeType) { httpRequest.overrideMimeType('text/xml'); // See note below about this line } } else if (window.ActiveXObject) { // IE try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!httpRequest) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } httpRequest.onreadystatechange = function() { alertContents(httpRequest); }; httpRequest.open('GET', url, true); httpRequest.send(''); } function alertContents(httpRequest) { if (httpRequest.readyState == 4) { if (httpRequest.status == 200) { var response = httpRequest.responseXML.documentElement; var n = response.getElementsByTagName('from')[0].firstChild.nodeValue; document.getElementById("returned_value").innerHTML = n; } else { alert('There was a problem with the request.'); } } } Codice:
<html> <head> <script type="text/javascript" src="ajax.js"></script> </head> <body> <form action=""> <select name="prova" onchange="makeRequest('getdata.php')"> <option value="1">prova1</option> <option value="2">prova2</option> <option value="3">prova3</option> </select> </form> <span id="returned_value"></span> </body> </html> Codice:
<?php // XML ajax response echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <note> <to>me</to> <from>you</from> <heading>Reminder</heading> <body>abcdefgh</body> </note>"; ?> linea 42 carattere 3 'null' è nullo o non è un oggetto che sarebbe la riga "document.getElementById("returned_value").innerHTML = n;" ma da errore qualsiasi cosa scriva al posto di questo. non riesco proprio ad uscirne. se provo ad usare responseText vedo correttamente l'xml che mi ritorna.
__________________
![]() |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
Ho provato e a me funge...
__________________
http://www.tevigroup.it/ |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Mar 2006
Città: Bergamo
Messaggi: 2499
|
trovato la cazzata...manca header('Content-type: text/xml'); in getdata.php
uhmmm ti funziona senza? interessante
__________________
![]() |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
Si senza, io ho una servlet che mi fa questo
Codice:
String result = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; result += "<note>"; result += "<to>me</to>"; result += "<from>you</from>"; result += "<heading>Reminder</heading>"; result += "<body>abcdefgh</body>"; result += "</note>"
__________________
http://www.tevigroup.it/ |
![]() |
![]() |
![]() |
#5 |
Senior Member
Iscritto dal: Mar 2006
Città: Bergamo
Messaggi: 2499
|
ok grazie...ora posso procedere
![]()
__________________
![]() |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 04:43.