12345678910111213141516171819202122232425262728293031323334353637
  1. /*!
  2. * Copyright (c) 2015-2016, Okta, Inc. and/or its affiliates. All rights reserved.
  3. * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
  4. *
  5. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
  6. * Unless required by applicable law or agreed to in writing, software
  7. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  8. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. *
  10. * See the License for the specific language governing permissions and limitations under the License.
  11. */
  12. var $ = require('jquery');
  13. function jqueryRequest(method, url, args) {
  14. var deferred = $.Deferred();
  15. $.ajax({
  16. type: method,
  17. url: url,
  18. headers: args.headers,
  19. data: JSON.stringify(args.data),
  20. xhrFields: {
  21. withCredentials: true
  22. }
  23. })
  24. .then(function(data, textStatus, jqXHR) {
  25. delete jqXHR.then;
  26. deferred.resolve(jqXHR);
  27. }, function(jqXHR) {
  28. delete jqXHR.then;
  29. deferred.reject(jqXHR);
  30. });
  31. return deferred;
  32. }
  33. module.exports = jqueryRequest;