Skip to main content

Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks will be deprecated in jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.

var form_data = {
    'csrf_test_name': $("input[name=csrf_test_name]").val() ? $("input[name=csrf_test_name]").val() : $.cookie('csrf_cookie_name'),
    'snippet_id': 0
  };

  var jqxhr = $.ajax({
    type: 'POST',
    url: '/mypage/hide',
    dataType: 'json',
    data: form_data,
    beforeSend: function () {
      console.log("before send");
    }
  }).done(function (data) {
    
    if (data.status == 'success') {
      console.log(data.message);
    } else {
      alert(data.message);
    }

  }).fail(function () {
    alert('Connection failed!');

  }).always(function () {

    console.log("always event");
  });

  // perform other work here ...
  // Set another completion function for the request above
  jqxhr.always(function () {
    console.log("second always");
    // remove loading animation
  });