Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.53 KB | None | 0 0
  1. var add_smessage_form = document.getElementById("add_smessage_form");
  2.     if (add_smessage_form != null) {
  3.         $(add_smessage_form).submit(function () {
  4.             var uri = '/support/addSupportMessage';
  5.             var data = $(add_smessage_form).serialize();
  6.  
  7.             const cooki = cookie();
  8.             document.cookie = 'CSRF-TOKEN=' + cooki;
  9.  
  10.             $.ajax({
  11.                 url: uri,
  12.                 data: data,
  13.                 timeout: 5000,
  14.                 crossDomain: true,
  15.                 headers: {'X-CSRF-TOKEN': cooki},
  16.                 xhrFields: {
  17.                     withCredentials: true
  18.                 },
  19.                 type: "POST",
  20.  
  21.                 beforeSend: function () {
  22.                     NProgress.start();
  23.                 },
  24.  
  25.                 complete: function () {
  26.                     NProgress.stop();
  27.                 }
  28.             })
  29.                 .done(function(data) {
  30.                     switch(data.type) {
  31.                         case 'OK':
  32.                             setTimeout(function() {window.location = "/support";}, 5000);
  33.                             $('#add_support_messag_div').html('<div class="alert alert-success">' + data.message + '</div>');
  34.                             break;
  35.                         case 'ERROR':
  36.                             $('#add_support_message_div').html('<div class="alert alert-danger">' + data.message + '</div>');
  37.                             break;
  38.                     }
  39.                 });
  40.             return false;
  41.         });
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement