PDA

View Full Version : getting HTML using responseText



smeshy123
Jun 20th, 2006, 04:11 PM
I have a php page, that my ajax page (this is my first time using ajax, and pretty much javascript as well) calls and sends a variable to. Then I take that variable and create a formatted portion of a table (text and HTML) and output that data back to my main page with the Javascript AJAX call on it. Here is the code:



function changecategory() {
var char=document.getElementById("changecat");
var cat = char.options[char.selectedIndex].text;
var string = "category=" + cat;
alert(string);
var oXmlHttp = zXmlHttp.createRequest();
oXmlHttp.open("get", "changecatbak.php?" + string, true);
oXmlHttp.onreadystatechange = function () {
if (oXmlHttp.readyState == 4) {
var data = oXmlHttp.responseText;
var test = document.getElementById("contactlist");
document.getElementById("contactlist").innerHTML = oXmlHttp.responseText;
}
};
oXmlHttp.send(null);
}


It only brings back the text and a single HTML element, which in this case is a checkbox button. So my question is, can I bring back HTML formatting text from the php page into the AJAX page? If so, how?

Thanks!

Smeshy

smeshy123
Jun 20th, 2006, 04:14 PM
Nevermind! I figured it out, about 2 mins after I ask a question I answer it, every time! Ok...so it turns out that my problem was that on my main page with the AJAX, I had the <table></table> and in the php page I was formatting just the <tr><td>'s...etc. When I moved the <table></table> to my PHP page to output to my AJAX page, it worked!