Advertisement
Guest User

Untitled

a guest
Nov 9th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.06 KB | None | 0 0
  1. $(document).ready(function () {
  2.  
  3.     $('#submitRegistration').click(function () {
  4.         var username = $('#login').val();
  5.         var password = $('#password').val();
  6.         var header = $("meta[name='_csrf_header']").attr("content");
  7.         var token = $("meta[name='_csrf']").attr("content");
  8.         $.ajax({
  9.             type: "POST",
  10.             url: "/registration",
  11.             contentType: "application/json; charset=utf-8",
  12.             dataType: "json",
  13.             data: '{"username": "' + username + '", "password": "' + password + '"}',
  14.             beforeSend: function (xhr) {
  15.                 xhr.setRequestHeader(header, token)
  16.             },
  17.             success: function (data) {
  18.                 if (data.status === "OK") {
  19.                     window.location.href = "/main"
  20.                 } else {
  21.                     alert(data.errorMessage)
  22.                 }
  23.  
  24.             },
  25.             error: function (xhr, ajaxOptions, thrownError) {
  26.                 console.log(xhr.status + ": " + thrownError);
  27.             }
  28.         });
  29.     });
  30. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement