如何让回调错误在JavaScript中提醒?

问题描述:

我正在用PhoneGap构建应用程序。它在我的电脑上工作正常。但是当我安装它作为android应用程序它不起作用。它火alert('Oppps...something went wrong')如何让回调错误在JavaScript中提醒?

我有以下代码...

function getFloors(url, callback){ 
    var data = $.ajax({ 
       type: 'GET', 
       url: "http://example.com/all_test/get_floors.php" 
      }).done(callback).error(function(e){ 
       alert('Oppps...something went wrong') 
      }); 
    return data; 
}; 

让我们假设有一个像http://example.com/all_test/get_floors.php没有任何页面。

然后你可以在控制台中发现错误,如GET http://example.com/all_test/get_floorss.php 404 (Not Found)

我需要将该错误显示为警报。我的意思是我需要打印真正的错误,而不是alert('Oppps...something went wrong')。所以我可以找到移动中的问题。

我应该如何得到一个警报的错误(控制台上显示的内容)。

+1

也许'e'有你在找什么?注意:你正在使用一个不赞成使用的'.error'方法 - 从**文档**'.fail()方法取代了已弃用的.error()方法。' –

+0

@JaromandaX你的意思是'done(callback).error函数(e){ alert(e) });'....它返回[object Object]。 –

+0

好吧,如果你看**文档** ...'.fail(function(jqXHR,textStatus,errorThrown)'http://api.jquery.com/jquery.ajax/ –

看看这个文件

http://api.jquery.com/jQuery.ajax/#jqXHR

error(function(e)e返回返回以下属性,你可以在您的处置

readyState的

的responseXML并打印jqXHR对象/或responseText - 当底层请求使用x响应 ml和/或文本,分别

状态

状态文本

我认为你正在努力寻找的e.responseTexte.responseXML

+0

e.responseText和e.responseXML都未定义。 e.statusText只返回“错误”。 e.error返回类似'function(){if(h){var c = h.length;!function g(b){n.each(b,function(b,c){var d = n.type C); “功能” === d a.unique && k.has(C)|| h.push(c)中:C && c.length && “串” == d &&克(C)})}(参数),d?!? f = h.length:b &&(e = c,j(b))} return this}'。有什么我可以尝试吗? –

+0

“e.status”或“e.statusText”返回什么?错误50x?或错误40x? –

+0

e.status为我工作........谢谢 –