Ajax and JSON request problems
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
PHPDevShell |
Fix Released
|
High
|
TitanKing |
Bug Description
PHPDevShell version 3.0.1 and 3.0.3.
The Ajax menu type (10) currently always assume that HTML will be returned from the server when it may also be XML or JSON. It also by default injects some LightBox script into its results which obviously breaks any XML or JSON results. The Lightbox html looks like this:
<script type="text/
<div id="PHPDS_
Currently the only way to get around this problem is to configure the menu as a Standard menu (1 - Standard Web Page) and to set its Theme to empty. Then lastly one have to also add the header "application/json" using: header(
I have two suggestions:
Suggestion A) Add two more menu types namely Ajax XML and JSON and let it behave in the correct way.
Suggestion B) Change the Ajax menu to read an additional parameter or request header to determine the output result. For example, one should be able to either add a URL parameter such as datatype=ajax / datatype=json or perhaps even better the "Accept:" request header should be adhered to. For example a standard JQuery JSON request header looks like this: "Accept: application/json text/javascript" and PHPDevshell can pick up on this to know how to respond to the request.
I personally do not like the fact that one has to pass a URL parameter through to let PHPDevShell know what it is dealing with. If one forgets to add ajax=true to the Ajax request URL the server returns with an invalid or empty response which buggers the handling on the Javascript side. This is actually quite a hard problem to try and resolve.
We also need to look at the error responses when dealing with Ajax/JSON. If it is up to the end-developer to implement better Ajax error handling mechanisms then it should at least be documented well.
Changed in phpdevshell: | |
status: | New → Confirmed |
assignee: | nobody → TitanKing (titan-phpdevshell) |
Changed in phpdevshell: | |
status: | Confirmed → Fix Committed |
Changed in phpdevshell: | |
status: | Fix Committed → Fix Released |
I did a bit of research on the topic of the "Accept: application/json" header that is sent with the Ajax request. This header along with "X-Requested-With: XMLHttpRequest" is only sent by some javascript libraries such as JQuery and MooTools so one can not always rely that it will be there. I think the best would be to first test for the header and if that doesn't exist one should check for a URL parameter such as datatype=json.