Does Axios use AJAX by default?

Asked

Viewed 69 times

-1

Person, a question when studying Xios came up. When I use the default http call with Xios.get(url). then(), is this already considered as an AJAX call? Or is it necessary to add something else?

  • 2

    An AJAX is an asynchronous Javascript request, so yes, the request using the axios is a form of AJAX.

1 answer

3


In browsers is yes, by default it uses the XmlHttpRequest (alias ajax), can check in the source code:

But if it’s "back-end" (inside the node.js) will use the following libs:

var http = require('http');
var https = require('https');
var httpFollow = require('follow-redirects').http;
var httpsFollow = require('follow-redirects').https;
var url = require('url');
var zlib = require('zlib');

Remember that you can create your own "adapter" However you can change the "adapter" this way:

var settle = require('./../core/settle');

module.exports = function myAdapter(config) {
  return new Promise(function(resolve, reject) {
  
    var response = {
      data: responseData,
      status: request.status,
      statusText: request.statusText,
      headers: responseHeaders,
      config: config,
      request: request
    };

    settle(resolve, reject, response);

  });
}

May apply until the API fetch(), or you can solve by applying as well:

axios({
    url: 'foo/bar',
    ...
    adapter: function (config) {
        seu adaptador aqui dentro
    }
});

Or you can apply GLOBALLY:

axios.defaults.adapter = function () {
    seu adptador aqui dentro
};

Browser other questions tagged

You are not signed in. Login or sign up in order to post.