I’m currently working on a ToDo List for a college project, and I’d like to take on some AJAX, but I’d also like to make it work both ways (pure PHP and also with AJAX, if JavaScript’s available).
On my PHP approach, I use some HTML code embeded (like <td>$value</td>). On AJAX, I guess I would strip the HTML from the PHP file, take the printing results part away, and I would just add it to the JavaScript (with jQuery) code, but that would render the pure PHP approach unusable.
With the AJAX examples I’ve seen, the PHP file that processes the data can no longer work stand-alone, and would not produce any human-friendly results if weren’t for the AJAX side. So my question is: do you know of a working example of an AJAX and PHP approach together, or could you provide one, please?
I hope I made myself clear, since I’m not a native english speaker. In case you need clarification, please let me know.
I would suggest using ‘smart’ php requests where the output is dependent on the parameters passed to PHP.
to get data as a webpage, just make a request to the php file
index.phpbut to get data as json, make the same request using a query string
index.php?type=JSONYour php will have to have a bit more logic behind it, but it allows you to request the same information from the same place in a different format. This also would allow you to expand formats to include RSS, PDF(if you’ve got the file available), or anything else.