Hi! I am currently developing a kind of CMS framework administration system, in which I would need to fetch HTML code through Ajax from a database along with other data and put in input fields. Fetching ordinary strings and values through the PHP generated XML document works perfect, but as soon as I fetch html content, the whole thing bugs out and gives me NULL-values. The $html gets into the mysql database through a WYSIWYG editor. As longs as the row contains no tags, the XML fetching in javascript works flawlessly. This is my generated XML document: (Short-tags on the server is turned off) <?php header("Content-Type: application/xml"); ?> <?xml version="1.0" encoding="ANSI"?> <?php $id = $_GET['id']; $result = mysql_query("SELECT * FROM page WHERE ID ='$id'") or die(mysql_error()); while($row = mysql_fetch_array($result)){ $title = mysql_escape_string($row['title']); $html = mysql_escape_string($row['html']); echo " <DATA> <TITLE>$title</TITLE> <VISIBLE>$row[visible]</VISIBLE> <TEMPLATE>$row[templateID]</TEMPLATE> <HTML>$html</HTML> </DATA>"; } PHP: My javascript fetching code: onSuccess: function(transport){ var root = transport.responseXML; alert(transport.responseText); var pageTitle, pageHTML, pageVisible, pageTemplate; try{pageTitle = root.getElementsByTagName("TITLE")[0].firstChild.data}catch(e){debug(e)}; try{pageHTML = root.getElementsByTagName("HTML")[0].firstChild.data}catch(e){debug(e)}; if(!pageHTML) pageHTML = " "; PHP: In my alert, I get the full XML page. however, in the occurence of HTML in the $html, and not when $html is just plain text, the try{} throws these errors: TypeError: root.getElementsByTagName("TEMPLATE")[0] is undefined TypeError: root.getElementsByTagName("VISIBLE")[0] is undefined TypeError: root.getElementsByTagName("HTML")[0] is undefined TypeError: root.getElementsByTagName("TITLE")[0] is undefined Code (markup): Not just for the HTML block, but for everything!! My guess is that html in an XML document screws with the XML DOM. Is it possible to fetch HTML through XML? I haven't tried with JSON yet, is that possible? Heard it's quicker, but that doesn't really matter. Thanks in advance!!
Doh, thank you very much! Exactly what I've been looking for! I've even been to W3Schools before, but searching after a new way to fetch the results, not so send them.
You can always use RegEx to extract data from HTML function fetchData(tag, data){ reg = new RegExp("<" + tag + ">([^<>]+)<\/" + tag + ">", "i"); return reg.exec(data)[1]; } alert("title", transport.responseText);