ERLEDIGT
JA
JA
ANTWORTEN
12
12
ZUGRIFFE
555
555
EMPFEHLEN
-
Wie der Titel schon besagt bekomme ich nur responseText aber nicht responseXML zurück.
Vielleicht habe ich was übersehen wäre jedenfalls für schnelle Hilfe echt dankbar.
ajax.js
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
var ajax_id = 0; AJAX=function(args) { var ajax = args; //set ajax id ajax.id = ajax_id++; ajax.log = ''; ajax.request = function() { var now = new Date(); try{ //creating XMLHttpRequest-Object this.xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); //set transfermode this.method=(typeof this.method == 'undefined') ? 'GET' : this.method; this.log += 'ajax.method:\t\t\t\t'+this.method+'\n'; //preparing data this.data=(this.data || ''); this.log += 'ajax.data:\t\t\t\t'+this.data+'\n'; //preparing postData this.postData=(this.method=='GET') ? null : this.data; this.log += 'ajax.postData:\t\t\t'+this.postData+'\n'; //preparing URL this.URL=(this.method=='POST' || this.data=='') ? this.URL : ( (this.URL.indexOf('?')==-1) ? this.URL+'?'+this.data : this.URL+'&'+this.data ); this.log += 'ajax.URL:\t\t\t\t\t'+this.URL+'\n'; //creating timestamp this.timestamp = now.getTime(); this.log += 'ajax.timestamp:\t\t\t'+this.timestamp+'\n'; //initializing request this.xhr.open(this.method,this.URL,true); //set post header if(this.method=='POST') { this.xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); this.xhr.setRequestHeader("Content-length", this.postData.length); this.xhr.setRequestHeader("Connection", "close"); } //disabling cache if nocache is set if(!typeof this.nocache || this.nocache) { this.xhr.setRequestHeader("If-Modified-Since", "Thu, 01 Jan 1970 00:00:00 GMT"); } //targeting callback function if(typeof this.callback == 'function') { this.xhr.onreadystatechange = function() { var readyState=ajax.xhr.readyState; var status=(readyState==4)?ajax.xhr.status:null ajax.log += 'ajax.xhr.readyState:\t\t'+readyState+'\n'; ajax.log += 'ajax.xhr.status:\t\t\t'+status+'\n'; ajax.log += 'ajax.xhr.statusText:\t\t'+ajax.xhr.statusText+'\n'; ajax.log += 'ajax.xhr.responseText:\t\t'+ajax.xhr.responseText+'\n'; ajax.log += 'ajax.xhr.responseXML:\t\t'+ajax.xhr.responseXML+'\n'; if(readyState==4 && status==200) { ajax.callback(ajax,readyState,status); } }; } else if(typeof this.destination == 'object') { this.xhr.onreadystatechange = function() { var readyState=ajax.xhr.readyState; var status=(readyState==4)?ajax.xhr.status:null ajax.log += 'ajax.xhr.readyState:\t\t'+readyState+'\n'; ajax.log += 'ajax.xhr.status:\t\t\t'+status+'\n'; ajax.log += 'ajax.xhr.statusText:\t\t'+ajax.xhr.statusText+'\n'; ajax.log += 'ajax.xhr.responseText:\t\t'+ajax.xhr.responseText+'\n'; ajax.log += 'ajax.xhr.responseXML:\t\t'+ajax.xhr.responseXML+'\n'; if(readyState==4 && status==200) { ajax.destination.innerHTML = ajax.xhr.responseText; } }; } //send request // this.log += 'xhr.getAllResponseHeaders:\t\t'+xhr.getAllResponseHeaders()+'\n'; this.xhr.send(this.postData); this.log += 'xhr.send()\n'; } //errorhandling catch(e) { try{ this.log += 'ERROR:AJAX.request()\n'; alert(this.log); } catch(e){} } } //return ajax object return ajax; }
Anwendung:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
function sendRequest(args){ //var args = {'method':'POST','data':'','URL':'ajax.php','nocache':true,'destination':document.getElementById('x')}; AJAX(args).request(); } function ajax_catch(ajax,readyState,status) { //readyState = ajax status //status = http status if(readyState==4 && status==200) { insert_person(ajax.xhr.responseText); } } var pCount = 0; function person_remove(id) { var child = document.getElementById(id); document.getElementById("persons").removeChild(child); } function insert_person(responseText) { pCount++; var newChild = document.createElement("div"); var attrId = document.createAttribute("id"); attrId.nodeValue = "p"+pCount; var attrClass = document.createAttribute("class"); attrClass.nodeValue = "person"; newChild.setAttributeNode(attrId); newChild.setAttributeNode(attrClass); newChild.innerHTML = responseText; document.getElementById('persons').appendChild(newChild); } function person_add(type) { var args = {'method':'POST','data':'action=addPerson&type='+type,'URL':'ajax.php','nocache':true,'callback':ajax_catch}; sendRequest(args); }
-
Moin Chris,
wenn ein Request kein responseXML liefert, dann ist dies ein Anzeichen dafür, dass die Antwort kein gültiges XML ist.
Die Fehlerursache müsstest du daher in der Antwort suchen, und nicht im Skript.
-
oh mh ich habs so versucht:
aber vermutlich ist das so nicht richtig?Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
function ajax($action) { header("Content-type: text/xml"); echo "<?xml version=\"1.0\" ?>\n"; echo "<root>\n"; echo " <data>\n"; switch($action) { case "addPerson": echo " <innerHTML>\n"; include TEMPLATE_PATH."step1_person.tpl"; echo " <innerHTML>\n"; break; } echo " </data>\n"; echo "</root>"; }
EDIT: irgendwie will der code highlighter hier nicht ganz....
bug?kopie von oben -.-PHP-Code:echo "<?xml version=\"1.0\" ?>\n";Geändert von Da_Chris (21.07.10 um 04:30 Uhr)
-
Auf den 1. Blick würde ich sagen, dass das 2.
den Fehler produziert, das sollte besser so aussehen:Code :1
echo " <innerHTML>\n";
Code :1
echo " <[COLOR="Red"][B]/[/B][/COLOR]innerHTML>\n";
Ob es das dann schon war, kann ich nicht sagen, ohne den Inhalt von step1_person.tpl zu Kennen.
Falls es weiterhin nicht geht, poste besser die Ausgabe des PHP-Skriptes.
-
-
step1_person.tpl
die frage da auch muss ich html speziell in xml verkapseln?HTML-Code:<input type="hidden" name="person[][type]" value="1" /> <div class="person_attribute">Kind</div> <div class="person_attribute"><input type="checkbox" name="person[][opt1]" value="true" /> mit Essen</div> <div class="person_attribute">Kosten: xx €</div> <div class="person_attribute"><a class="person_delete" href="javascript:void(0);" onclick="person_remove(this.parentElement.parentElement.id)">-</a></div>
Habe das mit CDATA versucht nur ob das richtig so ist bin ich mir nicht sicher.
Das XML Fragment finde ich auch nicht so wirklich "wohlgeformt"...
EDIT:
Ah das mit der Highlighter Variante kannte ich noch nicht...
Die sollte mal im editor verlinkt werden
Meine XML Ausgabe sieht so aus:
Dabei bekomme ich folgenden Fehler:Code :1 2 3 4 5 6 7 8 9 10 11
<root> <data> <innerHTML> <input type="hidden" name="person[][type]" value="1" /> <div class="person_attribute">Kind</div> <div class="person_attribute"><input type="checkbox" name="person[][opt1]" value="true" /> mit Essen</div> <div class="person_attribute">Kosten: xx €</div> <div class="person_attribute"><a class="person_delete" href="javascript:void(0);" onclick="person_remove(this.parentElement.parentElement.id)">-</a></div> </innerHTML> </data> </root>
Ich muss also doch irgendwie den html-quelltext in der xml ordentlich einbetten.This page contains the following errors:
error on line 9 at column 11: Extra content at the end of the document
Below is a rendering of the page up to the first error.
Ausgabe:
Code :1
Kind mit EssenKosten: xx € - ]]>
Geändert von Da_Chris (21.07.10 um 05:00 Uhr)
-
Schreibe diese Zeile:
Code :1
<div class="person_attribute">Kosten: xx €</div>
mal so:
Code :1
<div class="person_attribute">Kosten:   xx €</div>
Warum: und € sind benannte Entitäten.
Diese fliegen aber nicht irgendwo herum, sondern werden in der DTD deklariert.
In einem HTML-Dokument kann man sie verwenden, weil sie dort in der DTD referenziert sind.
Dein XML hat aber keine DTD, somit sind dort diese benannten Zeichen unbekannt.
Die Unicode-Schreibweise kennt XML aber auf jeden Fall.
Du kannst dieses PHP-Skript, welches das XML zurückgeben soll, übrigens auch direkt in einigen Browsern öffnen.
Im FF wirst du dann bspw. folgendes sehen:XML-Verarbeitungsfehler: Nicht definierte Entität......
-
Eine andere Möglichkeit den Quelltext zu kapseln geht nicht?
Würde das nur ungern auf die Art machen da die templates geändert werden können...Google und die Forensuche beantworten 50% aller Fragen!
Pflichtlektüre: Das PHP Handbuch als Windows Help Datei
Bitte Benutzt für Source-Code immer die richtigen Formatierungstags:
[PHP]Für PHP diese Tags[\PHP] ... [HTML]Für HTML diese Tags[\HTML] ... [SQL]Für SQL diese Tags[\SQL] ... [CODE]Für sonstigen Code[\CODE]
Wenn mein Beitrag hilfreich war bitte ich um eine positive Bewertung.
-
Doch geht, verwende eine CDATA-Sektion, da ist es egal, was drinnen steht, weil es nicht geparst wird... es sind dann schlicht Zeichendaten.
Für deinen Fall ist das sicher das beste, denn momentan wird ja das was in <innerhtml/> steht zum Bestandteil der Knotenstruktur.
Ohne CDATA sind die Ergebnisse unabsehbar, wenn da Fremde ohne XML-Kenntnisse HTML-Code eingeben.
-
ja hab ich jetzt gemacht jetzt bekomme ich auch eine ausgabe... aber zuviel... das schliessende tag der CDATA wird mit ausgegeben...
xml:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13
<?xml version="1.0" ?> <root> <data> <innerHTML> <![CDATA[ <input type="hidden" name="person[][type]" value="1" /> <div class="person_attribute">Kind</div> <div class="person_attribute"><input type="checkbox" name="person[][opt1]" value="true" /> mit Essen</div> <div class="person_attribute">Kosten: xx €</div> <div class="person_attribute"><a class="person_delete" href="javascript:void(0);" onclick="person_remove(this.parentElement.parentElement.id)">-</a></div> ]]> </innerHTML> </data> </root>
EDIT:
mh hatte noch auf text gestellt gehabt
aber jetzt ist innerHTML plötzlich wieder leer
mein javascript sieht so aus:
Code javascript:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
function sendRequest(args){ //var args = {'method':'POST','data':'','URL':'ajax.php','nocache':true,'destination':document.getElementById('x')}; AJAX(args).request(); } function ajax_catch(ajax,readyState,status) { //readyState = ajax status //status = http status if(readyState==4 && status==200) { //alert(ajax.xhr.responseText); //alert(ajax.xhr.responseXML); insert_person(ajax.xhr.responseXML); } } var pCount = 0; function person_remove(id) { var child = document.getElementById(id); document.getElementById("persons").removeChild(child); } function insert_person(responseXML) { var innerHTML = responseXML.getElementsByTagName("innerHTML")[0]; alert(innerHTML.firstChild.nodeValue); pCount++; var newChild = document.createElement("div"); var attrId = document.createAttribute("id"); attrId.nodeValue = "p"+pCount; var attrClass = document.createAttribute("class"); attrClass.nodeValue = "person"; newChild.setAttributeNode(attrId); newChild.setAttributeNode(attrClass); newChild.innerHTML = innerHTML.firstChild.nodeValue; document.getElementById('persons').appendChild(newChild); } function person_add(type) { var args = {'method':'POST','data':'action=addPerson&type='+type,'URL':'ajax.php','nocache':true,'callback':ajax_catch}; sendRequest(args); }
Geändert von Da_Chris (21.07.10 um 05:09 Uhr)
-
So ich hab jetzt durch debuggen der objekte rausgefunden dass ich aus irgendeinem grund nextsibling verwenden muss...
Warum ist mir nicht so ganz klar. Vor alles was er wann verwendet ist mir schleierhaft....
Für Erklärungen und Verbesserungstips bin ich auch dankbar.
Und danke auch bis hierher Sven
Code javascript:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
function sendRequest(args){ //var args = {'method':'POST','data':'','URL':'ajax.php','nocache':true,'destination':document.getElementById('x')}; AJAX(args).request(); } function ajax_catch(ajax,readyState,status) { //readyState = ajax status //status = http status if(readyState==4 && status==200) { //alert(ajax.xhr.responseText); //alert(ajax.xhr.responseXML); insert_person(ajax.xhr.responseXML); } } var pCount = 0; function person_remove(id) { var child = document.getElementById(id); document.getElementById("persons").removeChild(child); } function insert_person(responseXML) { var innerHTML = responseXML.getElementsByTagName("innerHTML")[0]; pCount++; var newChild = document.createElement("div"); var attrId = document.createAttribute("id"); attrId.nodeValue = "p"+pCount; var attrClass = document.createAttribute("class"); attrClass.nodeValue = "person"; newChild.setAttributeNode(attrId); newChild.setAttributeNode(attrClass); newChild.innerHTML = innerHTML.firstChild.nextSibling.nodeValue; document.getElementById('persons').appendChild(newChild); } function person_add(type) { var args = {'method':'POST','data':'action=addPerson&type='+type,'URL':'ajax.php','nocache':true,'callback':ajax_catch}; sendRequest(args); }
-
Hi,
die Browser interpretieren die Zeilenumbrüche im XML-Dokument unterschiedlich. So wird im FF ein #text-Objekt eingefügt, welches mit firstChild angesprochen wird. Im IE dagegen erreichst du mit firstChild bereits die gesuchte #cdata-section. An diesem Punkt musst du auch das Script anpassen, um alle Browser zufrieden zu stellen.
Beispiel:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
function insert_person(responseXML) { var innerHTML = responseXML.getElementsByTagName("innerHTML")[0]; pCount++; var newChild = document.createElement("div"); var attrId = document.createAttribute("id"); attrId.nodeValue = "p"+pCount; var attrClass = document.createAttribute("class"); attrClass.nodeValue = "person"; newChild.setAttributeNode(attrId); newChild.setAttributeNode(attrClass); [B] var objHlp = innerHTML.firstChild; while(objHlp.nodeName.search("cdata") == -1) objHlp = objHlp.nextSibling;[/B] newChild.innerHTML = [B]objHlp[/B].nodeValue; document.getElementById('persons').appendChild(newChild); }
Ciao
QuaeseVielleicht muss man manchmal vom Weg abkommen, um nicht auf der Strecke zu bleiben!
----
Der "Fortsetzungsroman" auf www.leuteforum.de
New kind to realize large scalable projects with jQuery: jQuery SDK
-
ahh ich habe befürchtet... scheiss browser unterschiede.....
Danke habs so implementiert.Google und die Forensuche beantworten 50% aller Fragen!
Pflichtlektüre: Das PHP Handbuch als Windows Help Datei
Bitte Benutzt für Source-Code immer die richtigen Formatierungstags:
[PHP]Für PHP diese Tags[\PHP] ... [HTML]Für HTML diese Tags[\HTML] ... [SQL]Für SQL diese Tags[\SQL] ... [CODE]Für sonstigen Code[\CODE]
Wenn mein Beitrag hilfreich war bitte ich um eine positive Bewertung.
Ähnliche Themen
-
[AJAX] kein Responsetext -> was mache ich falsch?
Von klanawagna im Forum Javascript & AjaxAntworten: 6Letzter Beitrag: 04.10.10, 09:23 -
Ajax responseText als HTML behandeln
Von zer0 im Forum Javascript & AjaxAntworten: 14Letzter Beitrag: 08.09.10, 18:25 -
Ajax ResponseText und alert
Von maythefunkbewitu im Forum Javascript & AjaxAntworten: 2Letzter Beitrag: 27.05.09, 14:56 -
[AJAX] responseText parsen
Von StupidBoy im Forum Javascript & AjaxAntworten: 4Letzter Beitrag: 14.02.09, 11:59 -
AJAX responseText senden
Von hugo1981 im Forum Javascript & AjaxAntworten: 6Letzter Beitrag: 03.02.08, 22:10





Zitieren



Login





