How to read a mySQL query (through PHP) into JavaScript variables using AJAX?
-
Hi, I have written an AJAX program that interfaces with a mySQL database through PHP pages. Inserting records is no problem at all but I have not figured out how to read a query into individual JavaScript variables yet. I'd like the query results to be in an object or array. Is my best bet to have the PHP page format the query results as an XML document? If so, where do you suggest that I get started here, as I've never created an XML document before? Thanks.
-
Answer:
You have the PHP page return text that creates a JavaScript array, e.g.: <?php echo "var myArray = new Array('apple', 'banana', 'pear');"; ?> Then you call eval() on that response text in JavaScript: eval(responseText);
John at Yahoo! Answers Visit the source
Related Q & A:
- How to return a value from .ashx file to javascript in a variable?Best solution by forums.asp.net
- How to write a complex query with doctrine?Best solution by Stack Overflow
- How to do a MySQL recursive query?Best solution by Stack Overflow
- How to make a MySql query faster?Best solution by Stack Overflow
- How to read a PDF file with PHP?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.