javascript - ajax post call to MVC action when i use [Authorize] gives status:200 error -


this ajax posts works fine when user authenticated, uanauthenticated user want use [authorize] redirecting login.javascript code below...

 $("#favorite").click(function () {      var favoritetext = $("#favorite").text();      var status = 1;      if (favoritetext == "remove favorite") {          status = 0;      } else {          status = 1;      }      $.ajax({          url: '@url.action("addfavorite", "movieprofile")',          data: {              status: status          },          datatype: 'json',          type: "post",          success: function (data) {              alert('sucsess');              if (status == 1) {                  $("#favorite").text("remove favorite");              } else {                  $("#favorite").text("add favorite");              }          },          error: function (xmlhttprequest, textstatus, errorthrown) {              alert('readystate:' + xmlhttprequest.readystate + ' status:' + xmlhttprequest.status + ', status text: ' + xmlhttprequest.statustext, +errorthrown);          }      });   }); 

and action is..

[httppost] [authorize] public actionresult addfavorite(int status) {  //code goes here } 

but gives error readystate:4 status:200, status text: ok.

since ajax-call, cannot redirect server. can redirect if it's direct request.

if want redirect on client-side, in error-handler:

error: function (xmlhttprequest, textstatus, errorthrown) {      window.location = "/login";      alert('readystate:' + xmlhttprequest.readystate + ' status:' + xmlhttprequest.status + ', status text: ' + xmlhttprequest.statustext, +errorthrown);                 } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -