locked
Result status code is always undefined

    Question

  • Hello

    I am using the following code stolen from http://msdn.microsoft.com/en-gb/library/windows/apps/hh452745.aspx:

    function xhrError(result) { var statusCode = result.status; var outputArea = document.getElementById("xhrOutput"); outputArea.innerHTML = "Unable to retrieve data at this time. Status code: " + statusCode; }

    My web service returns 500 when the database server is inaccessible. Testing on my local machine, I can see that Fiddler shows that 500 is returned when I stop the mysql service, but the debugger in VS Express 2012 always shows result.status as 'undefined'.

    Any suggestions gratefully received....

    Monday, January 14, 2013 1:04 AM

Answers

  • Hi munder,

    I suggest you directly use Visual Studio to debug the code and set breakpoint in the error callback function (of the WinJS.xhr call) so that you can watch the
    "result" variable passed in the callback and look for all the available properties on it.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Wednesday, January 16, 2013 8:32 AM
    Moderator

All replies

  • If the variable `result` is a XMLHttpRequest, it should has `status` property. In your case, the variable `result` may be not a XMLHttpRequest.

    Please check what is `result` by using following code.

    function xhrError(result) {
        console.log("result: ");
        console.dir(result);
        var statusCode = result.status; 
        var outputArea = document.getElementById("xhrOutput");
        outputArea.innerHTML = 
            "Unable to retrieve data at this time. Status code: " + statusCode;
    }
    The output of `console.log` and `console.dir` is displayed in JavaScript console of Visual Studio.

    Monday, January 14, 2013 6:03 PM
  • Hi munder,

    I suggest you directly use Visual Studio to debug the code and set breakpoint in the error callback function (of the WinJS.xhr call) so that you can watch the
    "result" variable passed in the callback and look for all the available properties on it.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Wednesday, January 16, 2013 8:32 AM
    Moderator
  • Thank you both for your help.

    It turns out that the problem was my having set too short a timeout on the request. By examining result.status, I could see that it had the value 'undefined'. It was only when I examined result that I saw it had the value 'canceled'. Increasing the timeout has solved the problem.

    Thanks again,

    Mick

    Wednesday, January 16, 2013 2:33 PM