Why .ajax always goes to success handler?

I used jQuery's `.ajax` function like: $.ajax({ type:"POST", url:"./index.php", data:{ajax_fetch:1,action:"fetch_devInfo",nwType:nw_type,devTSN:dev_tsn,devSTime:dev_sTime,devETime:dev_eTime,dev_gType:dev_graphType}, dataType:"xml", error:errHandler, success:function(xml,textStatus) { xml_process(xml,textStatus,$("div#cont-Dev"),"Device"); } }); // function for .ajax error callback function errHandler(xhr, statusText, error) { if (xhr.status == "0" && statusText == "error") { $("body").append('
Network down, try again later
'); } else if (xhr.status == "200" && statusText == "parseerror") { window.location="./login.php"; } } My assumption is: if `.ajax` success, then the server must return it a XML file (identified by its header header("Content-type: text/xml")), that's why I specify the dataType as "xml"; however, if it failed (for example: session time out), `index.php` will redirect user to the `login.php`. In that case, the response is some HTML, shouldn't `.ajax` go to the function `errHandler`? Why does it always go to the success handler?
stackoverflow.com/questions/199099/…

以上就是Why .ajax always goes to success handler?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏