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('<div class="ui-state-error ui-corner-all" id="error">Network down, try again later</div>');
}
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?