How do I trap a return of 403 in the new version
How do I trap a return of 403 in the new version
wjhumphreys
Posts: 52Questions: 9Answers: 5
I'm getting a lot of conflicting information on how to trap return data from an Ajax call.
This is MS MVC based but Im returning
context.HttpContext.Response.StatusCode = 403;
context.Result = new JsonResult
{
Data = new
{
Error = "NotAuthorized",
LogOnUrl = urlHelper.Action("LogOn", "Account")
},
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
if a session has expired.
Ive tried using
"dataSrc": function (json) {
alert(json.data);
return json.data;
}
but the json returned is blank and I cannot check for the 403 unless Im missing something.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
At the moment you would need to provide
ajax
as a function and define your own$.ajax()
call with whatever error handling you need.The
ajax.dataSrc
option is designed simply to transform the data retrieved from the server from one form into another, and has no access to the underlying XHR object.Extending DataTables abilities here is certainly something I want to look at - thanks for flagging it up.
Allan
Could you give me a simple example of this as I cant quite work out what is to go where.
I'm currently using
How does that translate to this?
The documentation probably needs an example of this I guess. You would do something like:
Obviously you will fill out the
$.ajax()
call as you need using standard jQuery options.Allan
Ahhh that makes more sense. I definitely think this is something you need to update in the documentation as this alone solves GETs that are to long, removing data from posts that isn't required. I have no doubt this is really something to people like myself that like full control and hand everything over to the server-side of things but without it some things are a bit of a pain.
:-)