- Preventing Cached AJAX Requests
- Debugging AJAX Code with FireBug
- Creating a Database Connection
Creating a Database Connection
Every developer should be aware of the following trick when creating a database connection with AJAX and PHP. When responding with XML data from the server, PHP’s header method allows you to set the Content-Type of the file, which needs to be application/xml. The following line of code simply constructs an XML file with strings and writes them to the page via PHP:
header("Content-Type: application/xml; charset=UTF-8");
Without this line of code, the response may not be seen as valid XML, which will break your request.
I hope that these tips and tricks save you some time when developing AJAX-enabled applications. They’ve helped me in numerous situations.