哪里可以找到明确的jquery ajax调用错误信息?
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?
我试图找到一个在我的项目中发生错误的地方,以便能够从那里抛出错误消息 。 p>
在我正在调试的项目中,执行ajax post调用。 在PHP早期的某处,导致错误的代码正在执行。 就我而言, PHP代码失败: p>
在某些时候调用的ajax代码: p>
在fail方法中,错误变得清晰,但它存储在一个巨大的html响应中,因此难以从整个值中获取。它存储在 这只是值的一部分,包含导致错误的行号。 p>
有没有人知道这个ajax失败的响应文本来自何处以及是否可以获得更清晰的消息而不是大的html输出字符串? p>
DIV>解析错误 code>导致了问题。 尝试从布尔变量中提取数组值。 但在那个地方,没有任何问题,代码继续运行。 p>
if($ booleanValue ['not-existing-arrayvalue'] =='true'){}
code> pre>
var call = $ .ajax(options );
call.done(function(result){...})
.fail(function(xhr,text_status){...}
code> pre>
xhr.responseText: code> p> \中 n
&lt; br /&gt;↵&lt; font size ='1'&gt;&lt; table class ='xdebug-error xe-notice'dir ='ltr'border ='1'cellsacing ='0'cellpadding ='1'&gt;↵&lt; tr&gt;&lt; th align ='left'bgcolor ='#f57900'colspan =“5”&gt;&lt; span style ='background-color:#cc0000; 颜色:#fce94f; font-size:x-large;'&gt;(!)&lt; / span&gt;注意:未定义的索引:在“C:\ workspace \ project \ class.php”中的第&lt; i&gt;行14&lt;&lt; i&gt; 14&lt; ; / i&gt;&lt; / th&gt;&lt; / tr&gt;↵&lt; tr&gt;&lt; th align ='left'bgcolor ='#e9b96 e'colspan ='5'&gt;调用堆栈&lt; / th&gt;
code> pre>
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.