SHARE
TWEET

Untitled

a guest Oct 21st, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ajax(url, data, $target, method, replaceWith) {
  2.     if ($target === undefined || $target == '') {
  3.         console.log($target);
  4.         $target = $('#body');
  5.     } else {
  6.         $target = $($target);
  7.     }
  8.     if (data === undefined) {
  9.         data = [];
  10.     }
  11.     if (method === undefined) {
  12.         method = 'GET';
  13.     }
  14.     if (replaceWith === undefined) {
  15.         replaceWith = false;
  16.     }
  17.     if ($($target).length == 0) {
  18.         console.log('target : ' + $target + ' inexistant');
  19.         console.log(1);
  20.         console.log($target);
  21.         $target = $('#body');
  22.     }
  23.  
  24.     $target.html('<img src="/dex2_loader.gif">');
  25.     console.log(data);
  26.     options = {
  27.         url: url,
  28.         method: method,
  29.         data: data,
  30.         headers: {
  31.             'X-CSRF-TOKEN': $('[name=_token]').val()
  32.         }
  33.     }
  34.  
  35.     $.ajax(options)
  36.         .done(function (html) {
  37.             if (replaceWith) {
  38.                 $target.replaceWith(html);
  39.             } else {
  40.                 $target.html(html);
  41.             }
  42.         }).fail(function (jqXHR, textStatus) {
  43.         if (jqXHR.status == 401) {
  44.             window.location.href = "/login";
  45.         }
  46.         $target.html(jqXHR.responseText);
  47.     })
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top