Advertisement
kernel_memory_dump

Ajax Spring Security MVC REST

May 27th, 2015
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function ajaxTest() {
  3.         var obj = {};
  4.         obj.name = "check this outa";
  5.    
  6.         alert(obj+"");
  7.         var token = $("meta[name='_csrf']").attr("content");
  8.         var header = $("meta[name='_csrf_header']").attr("content");
  9.            $.ajax({
  10.                beforeSend: function(xhr) {
  11.                     xhr.setRequestHeader("Accept", "application/json");
  12.                     xhr.setRequestHeader("Content-Type", "application/json");
  13.                     xhr.setRequestHeader(header, token); },
  14.             //    url: 'http://localhost:8080/Restaurant/rest3/',
  15.                 url: 'http://localhost:8080/Restaurant/test/rest/ingredient/add',
  16.                 data: JSON.stringify(obj),
  17.                 type: "POST",
  18.                 dataType: "json",
  19.                 processData:false ,
  20.                 success: function (result) {
  21.                     switch (result) {
  22.                         case true:
  23.                             alert(result);
  24.                             break;
  25.                         default:
  26.                             alert(result);
  27.                     }
  28.                 },
  29.                 error: function (xhr, ajaxOptions, thrownError) {
  30.                 alert(xhr.status);
  31.                 alert(thrownError);
  32.                 }
  33.             });
  34.    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement