Axios: Make AJAX GET Requests

10/10/2019 1:06:22 AM

Below are multiple ways to make a GET request with the Axios AJAX library.


function function__axios__get_1()
{
    var url = "/api/home/getdate/";

    axios.get(url)
        .then(function (response)
        {
            console.log(response);

            var result = response.data;
            console.log(result);
        })
        .catch(function (error)
        {
            console.log(error);
        });
}


function function__axios__get_2()
{
    var url = "/api/home/getdate/?timezone=utc";

    axios.get(url)
        .then(function (response)
        {
            console.log(response);

            var result = response.data;
            console.log(result);
        })
        .catch(function (error)
        {
            console.log(error);
        });
}


function function__axios__get_3()
{
    var url = "/api/home/getdate/";
    var params = {
        timezone: "utc"
    };

    axios.get(url, { params })
        .then(function (response)
        {
            console.log(response);

            var result = response.data;
            console.log(result);
        })
        .catch(function (error)
        {
            console.log(error);
        });
}


function function__axios__get_4()
{
    var url = "/api/home/getdate/";

    var axiosConfig =
    {
        method: "get",
        url: url
    };

    axios(axiosConfig)
        .then(function (response)
        {
            console.log(response);

            var result = response.data;
            console.log(result);
        })
        .catch(function (error)
        {
            console.log(error);
        });
}


function function__axios__get_5()
{
    var url = "/api/home/getdate/";

    var axiosConfig =
    {
        method: "get",
        url: url,
        params: {
            timezone: "utc"
        }
    };


    axios(axiosConfig)
        .then(function (response)
        {
            console.log(response);

            var result = response.data;
            console.log(result);
        })
        .catch(function (error)
        {
            console.log(error);
        });
}