Is it possible to return multiple items via AJAX and PHP? I am reading up on it and it seems just l开发者_如何学JAVAike an echo in PHP and responseText via Javascript. Can I return an array of items via PHP and convert it into Javascript or HTML?
It depends on the data format your PHP response is sending - it sounds like the examples you're seeing are just plain text. The best format in my opinion is JSON which can send an array of multiple results, and even a multi-dimensional array many levels deep.
See json_encode()
in PHP and JSON examples on jquery.com.
You can use the JSON format to return multiple values in AJAX: http://www.php.net/manual/en/function.json-encode.php
You can then decode it in javascript. This function allows you to do it in jQuery: http://api.jquery.com/jQuery.getJSON/
精彩评论