我有这样的$ .ajax方法
<form class="hidden code-box" method="GET" name="sample">
<div dir="ltr"><textarea class="php" name="codeguru"></textarea></div>
<div class="hint">This code is editable. Click Run to execute.</div>
<input type="submit" value="Run" />
<img class="hidden" style="vertical-align: middle;" alt="Try PHP " src="http://code.guru99.com/img/ajax-loader.gif" name="ajax-loader" title="Try PHP " />
<div class="hidden stdout"></div>
<div class="hidden stderr"></div>
</form>
$.ajax({
type: 'GET',
url: '/exec.php',
dataType: 'JSONP',
data: {code : code},
success: function(data)
{
//alert(data.result);
var data = data.result;
$(loader).addClass('hidden');
var stdout = $(form).children('.stdout');
if (data.search("Parse error")>0)
{
var str = data.replace('<b>Parse error</b>: ','');
$(stdout).html(str);
$(stdout).removeClass('hidden');
}
else
{
$(stdout).html(data);
$(stdout).removeClass('hidden');
}
},
jsonpCallback: 'mycallback',
error: function (xhr, ajaxOptions, thrownError,err,textStatus) {
var stdout = $(form).children('.stdout');
alert (stdout);
$stdout.html("Fatal error generated!!! Please check your code");
$stdout.removeclass('hidden');
}
});
现在,我要打印由于$ .ajax方法而生成的错误。我已经尝试过了
error: function (xhr, ajaxOptions, thrownError,err,textStatus) {
var stdout = $(form).children('.stdout');
alert (stdout);
$stdout.html("Fatal error generated!!! Please check your code");
$stdout.removeclass('hidden');
}
请帮忙
最佳答案
尝试以下操作:
$( document ).ajaxError(function( event, request, settings ) {
console.log(settings.url);
});
or
$.ajax({
type: 'GET',
url: '/exec.php',
dataType: 'JSONP',
data: {code : code},
success: function(data)
{
},
error: function(ts) { console.log(ts.responseText) }
});