rReLmy Posted October 21, 2007 Share Posted October 21, 2007 Hi I've got a problem to become html from a xml answer. What comes out is only the part before the first html Tag. I created my Script from this 2 Tutorials http://developer.mozilla.org/en/docs/AJAX:Getting_Started http://www.quirksmode.org/blog/archives/2005/12/the_ajax_respon.html *XML part* why does the js cut all after the first html Tag? I can't understand it... Here is the sample page http://www.rrelmy.ch/ajax/xml FF Extension says that the response coming clean. the js <script type="text/javascript"> function makeRequest(site) { 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, site); }; httpRequest.open('GET', 'ajax.php?site='+site, true); httpRequest.send(''); } function alertContents(httpRequest, site) { try { if (httpRequest.readyState == 4) { if (httpRequest.status == 200) { //alert(httpRequest.responseText); //document.getElementById('content').innerHTML = httpRequest.responseText; gen_site(httpRequest, site); } else { alert('There was a problem with the request.'); } } } catch( e ) { alert('Caught Exception: ' + e.description); } } function gen_site(xml, site) { var html = xml.responseXML.getElementsByTagName('replace'); //alert(html.length); for (var i=0;i<html.length;i++) { //alert(getNodeValue(html[i],'id')); document.getElementById(getNodeValue(html[i],'id')).innerHTML = getNodeValue(html[i],'html'); } set_navi(site); } function set_navi(site) { document.getElementById('n_home').setAttribute("class", "", 0); document.getElementById('n_scripts').setAttribute("class", "", 0); document.getElementById('n_'+site).setAttribute("class", "on", 0); } function getNodeValue(obj,tag) { return obj.getElementsByTagName(tag)[0].firstChild.nodeValue; //return obj.getElementsByTagName(tag)[0].firstChild.innerHTML; } function isset(varname) { if(typeof( window[ varname ] ) != "undefined") return true; else return false; } </script> sample ajax answer <?xml version="2.0" ?> <root> <replace> <id>content</id> <html>The Content <p>wont be shown, bliblablub</p></html> </replace> <replace> <id>panel</id> <html>Something Other<b>Blub</b></html> </replace> </root> Quote Link to comment Share on other sites More sharing options...
rReLmy Posted October 24, 2007 Author Share Posted October 24, 2007 Thx for your answer. After Hours of searching and trying i've found the solution! Really You have to put the CDATA thing around the "html" A sample <root> <replace> <id>content</id> <html><![CDATA[The Content <p>wont be shown, bliblablub</p>]]></html> </replace> <replace> <id>panel</id> <html><![CDATA[something Other<b>Blub</b>]]></html> </replace> </root> The JS Code in my first Post should work with it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.