views:

217

answers:

2

i have a jquery .ajax post type Json and an MVC controller with an [Authorize] attribute. on the return Jquery carries out "success" if user is authorized, but never carries out the "fail". how to handle when user is not authorized?

 $.ajax({
               type: "POST",
               url: "/index",
               dataType: "json",
               data: { ID:id, Name:name },
               success:function(data){...},
               fail:function(){...}
  });
+4  A: 

error: not fail:

http://docs.jquery.com/Ajax/jQuery.ajax#options

Check out the request in firebug to see the request in real time, will make your life much, much easier

Chad Grant
+2  A: 

The correct syntax is:

$.ajax({
               type: "POST",
               url: "/index",
               dataType: "json",
               data: { ID:id, Name:name },
               success:function(data){...},
               error:function(){...}
  });

Here's a similar post: json-parameters-auto-convert-to-lowercase-when-ajax-request-made-to-mvc-action-m

Jose Basilio