import Common from '../../common/Common';

export const ajaxApi = (url, datas) => {
  return new Promise((resolve, reject) => {
    $.ajax({
      url: Common.getApiUrl2(url),
      type: 'post',
      contentType: 'application/json',


      data: JSON.stringify(datas),

      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};

export const ajaxApiGet = (url, datas) => {
  return new Promise((resolve, reject) => {
    $.ajax({
      url: Common.getApiUrl2(url),
      type: 'get',
      contentType: 'application/json',
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};

