Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. $(document).ready(function () {
  2.  
  3. $('#ValidateUser').form(
  4. {
  5. on: 'submit',
  6. fields: {
  7. username: {
  8. identifier: 'username',
  9. rules: [{
  10. type: 'empty',
  11. prompt:'Username cannot be empty'
  12. }]
  13. },
  14. password: {
  15. identifier: 'password',
  16. rules: [{
  17. type: 'empty',
  18. prompt:'Password cannot be emtpy'
  19. }]
  20. }
  21. },
  22. onSuccess: function(event){
  23. event.preventDefault();
  24. $.api({
  25. url: '@Url.Action("Login", "Validation")',
  26. serializeForm: true,
  27. data: new FormData(this),
  28. onSuccess: function (result) {
  29. result.preventDefault();
  30. if (result.Success) {
  31. window.location = "/Dashboard/Dashboard";
  32. }
  33. else {
  34.  
  35. $('#formresult').append(result.Msg);
  36. }
  37. return false;
  38. }
  39. });
  40.  
  41. }
  42. });
  43. });
  44.  
  45. $(document).ready(function () {
  46.  
  47. $('#submitbutton').click(function(){
  48. $('#formresult').hide();
  49. });
  50.  
  51. $('#ValidateUser').form(
  52. {
  53. on: 'blur',
  54. fields: {
  55. username: {
  56. identifier: 'username',
  57. rules: [{
  58. type: 'empty',
  59. prompt: 'Username cannot be empty'
  60. }]
  61. },
  62. password: {
  63. identifier: 'password',
  64. rules: [{
  65. type: 'empty',
  66. prompt: 'Password cannot be emtpy'
  67. }]
  68. }
  69. },
  70.  
  71. onSuccess: function (event) {
  72. $('#formresult').hide();
  73. event.preventDefault();
  74. var formData = new FormData(this);
  75. $.ajax({
  76. url: '@Url.Action("Login", "Validation")',
  77. type: "POST",
  78. dataType: "json",
  79. contentType: "application/json; charset=utf-8",
  80. data: formData,
  81. contentType: false,
  82. processData: false,
  83. success: function (result) {
  84.  
  85. if (result.Success) {
  86. window.location = "/Dashboard/Dashboard";
  87. }
  88. else {
  89. $('#formresult').show();
  90. $('#formresult').text(result.Msg);
  91. }
  92.  
  93.  
  94. },
  95. error: function (result) {
  96. $('#formresult').show();
  97. $('#formresult').text(result);
  98. }
  99. });
  100. event.preventDefault();
  101. }
  102. });
  103.  
  104.  
  105. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement