PDA

View Full Version : AJAX - Displaying a table



bigcougar
26 Feb 2012, 11:19 PM
My page retrieves data from a MySQL database. The PHP script outputs a string of values that should produce a table on the page.


So far I have tried the following approaches without success

1. I get the PHP script to output the whole table as a response string to a request.

Echo "<table><td><tr>value1...........etc.....</table>";
Then I insert the response text into a <div> on the page using

innerHTML = response text (JavaScript)

This way I get the data out as a string of values.

2. I have the opening and closing table tags on the page <table></table>.
I then insert the rows again using innerHTML.


If I run the PHP script in 1 on its own, I get the table that I want on thescreen. I just cannot insert it in the place that I want on the page.


I know the methods I use are wrong. Any suggestions?

bigcougar
27 Feb 2012, 01:50 AM
I figured it out!

My method described in #1 works. I had made the mistake of removing the HTML tags from the response text, hence the strange output - no table.