I am trying to find a place where an error occurs in my project to be able to throw an error message from there.
Within the project I am debugging, an ajax post call is executed. Somewhere earlier in PHP the code causing the error is executing. In my case, a parse error
is causing the problem. An array value is tried to be fetched out of a boolean variable. But at that place, nothing goes wrong and the code continues to run.
Failing PHP code:
if ($booleanValue['not-existing-arrayvalue'] == 'true') { }
The ajax code that is been called at some point:
var call = $.ajax(options);
call.done(function (result) { ... })
.fail(function(xhr, text_status){ ... }
Inside of the fail method, the error becomes clear, but it is stored within a huge html response, so hard to fetch from the whole value. It is stored within xhr.responseText:
<br />↵<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>↵<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: selected in "C:\workspace\project\class.php" on line <i>14</i></th></tr>↵<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th>
This is just a part of the value, containing the line number causing the error.
Does anybody have an idea where this ajax failing response text comes from and if it is possible to get a cleaner message instead of a big html output string?
There is an error on line 14 of your class.php file, looks like you try to do an out of bounds call on an array. Therefore php returns an error response. Jquery detects that a error response is given a runs the fail function.
If you would look at the http request using a tool like fiddler then you could see that a http error code was returned instead of the normal 200. (Probably 500 - Internal Server Error).
If you don't get a clear php error message then you should check the log files and/or your server configuration.
Your problem is not in Ajax but in the code itself that returns the answer. From the side of the ajax you only need to parse the value from a large string.