Debugging Cjax
Debugging is an essential part of building ajax functionality. Without it, wouldn't know how you got this far.
To debug Cjax, you are required to use a browser console. Most modern browsers will already have a console or 'web inspector' bult-in.
Firefox, Chrome, Safari, IE, MS Edge, come included with one. Any of them will do nicely.
Firefox's plugin firebug is highly recommend to debug Cjax, as it includes many useful tools and is second to none compared to the others.
The console will feed you everything you need to know about what's hapenning with Cjax. From whether a file is loaded or not, to whether you enter a valid URL or if there is a server error, all this important and many times crusial information can be found on the console.
Particularly, there are certain things to watch out for, coming out of the console if you are testing any type of ajax call.
Keep in mind that web-inspector include many tabs. Cjax information can be found in the response tab, 95% of the time. The network tab, some times is useful as well to get information about whether a file has been loaded, or if a file has been hard-cached.
A simple look at this can give you so much information, and can help you be on your way to focus on building more things and spend less time wondering what went wrong.
- 1 Information about the URL, including any parameters passed
- 2 Response Status, it could be a forbidden status (403) or a server error (500), this information is useful for you to know where to look next.
- 3 Response Tab
- 4 Response, to get this information click the URL being displayed. If an error occured, most of the time you will be able to see that error here. That error is the key to keep you up and running as it includes what went wrong, and where you need to look to fix it.
-
Request status response
- This is a number status the server responds with depending on how the request went. 404, indicating that the controller file was not found. 500 indicating a server error, and there are other types of responses you may see. If there is a php error, the console always will give you the error message, unless you have error messaging completly turned off in your server settings. If you can't find the error on the console, the next place to look is your apache log files.
-
Console log
- If there is an error, for instance produced some where in the Cjax JS library, or in a plugin, the error will show up in the console. This error can give you explicit information of why something didn't work. Many times it will give the specific line number where the error occured, and you can click it and it will take you to the file in question.
- A plugin's dependencies could trigger one of the console errors. Dependencies are encapsulated within a plugin, they are loaded dynamically from the plugin directory by the plugin js file in cjax/plugins/[plugin-name], dependecies be found within the same directory.
-
No Error
- If you are looking at the console, you click on the URL, and view the response, and you do not see an error (and the response status is 200) - this could be something within the scope of your ajax controller. Try an exit test - eg: exit("It's getting here"); , then go to back to the console and if you see this message it's telling you that there is no problem, and the response you expect, is not a Cjax error, rather a product of your code or lack of.
-
Plugin Errors
-
If you are within a plugin, you can use CJAX.debug = true;, to enable further logs to show up in the console.
These methods described above, should be able to catch 99% of any issue you may experience. If you experience something different, be sure to create an issue in: https://github.com/ajaxboy/cjax/issues.