0

I have a JS/Html file and a PHP script. The PHP file creates a database connection and returns the result of the DB query.

The html page uses an ajax request to get the data and echos it back to the html page - but it is returned as text (xmlhttp.responseText), which I can display, but can't easily manipulate.

I would like to return the data as an array that I can process in JavaScript.

Is there a way for an ajax request to include the response as a variable, instead of as raw text?

If I can provide more information to make it easier to answer, let me know!

thanks!

2
  • 2
    Look into the JSON formatting. Php can echo your variables using json_encode(), which javascript can read and decode. Commented Dec 18, 2010 at 13:44
  • What about returning the response as XML with xmlhttp.responseXML? That allows you to access the individual nodes if the returned data is valid xml. The JSON option is probably easier though. Commented Dec 18, 2010 at 17:24

1 Answer 1

2

Check PHP, JSON and JavaScript usage

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.