locked
Handling ajax call errors (404, 500, etc.) RRS feed

  • Question

  • User-1795041401 posted

    Hi,

    I'm using $.ajax method to send some information (json) to the server. But I dont have the server function yet. So it will return 404 Not Found error.

    The thing is I want to handle this 404 error myself so the browser won't raise an error for it.

    My partial code is:

           $.ajax({
                url: url,
                data: model,
                type: "POST",
                dataType: "json",
                contentType: "application/json utf-8",
                success: function (result) {
                    console.log(result);
                },
                error: function (xhr, responseText) {
                    console.log("The ajax call returned error " + xhr.status + ": " + xhr.statusText);
                }
            });

    But when I run the code I see two errors on console. One is my "The ajax call...", and the other one is from the Google Chrome which is even before my error handler.

    POST http://localhost:5785/Admin/ut  404    (Not Found) -- I don't want to see this one --       jquery-2.0.3.js:7845
    
    The ajax call returned error  404: Not Found                                                             admin.js:165

    How can I manage that?

    Wednesday, February 12, 2014 11:50 PM

Answers