code_junkie

Is there ANY way to suppress the browser's login prompt on 401 response when using XmlHttpRequest

Nov 12th, 2011
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. $.ajax({
  2. type: "POST",
  3. url: postUrl + "/SomePageMethod",
  4. data: "{searchString:"" + escape(searchString) + ""}",
  5. contentType: "application/json; charset=utf-8",
  6. beforeSend: function(xhr) {
  7. xhr.setRequestHeader("X-MicrosoftAjax","Delta=true");
  8. },
  9. dataType: "json",
  10. success: onSuccess,
  11. error: onError
  12. });
  13.  
  14. function onError(xhr, e, textStatus) {
  15. var isAjaxRedirect = xhr.status == 200 && xhr.responseText.match(/pageRedirect/);
  16. if (isAjaxRedirect == "pageRedirect") {
  17. // forms authentication ticket expired
  18. location.href = "a session timeout page, or a login page or whatever";
  19. }
  20. }
Add Comment
Please, Sign In to add comment