The Get,post method of Axios

Source: Internet
Author: User
Tags node server

Learning Vue and Nodejs process, involving the Axios, today in order to test, wrote Get and post two methods to interact with node server, the result because the header and parameters for a long time, in this record, while sharing;

Because of the new contact Axios, in the test method, writing is very simple things, but can achieve the basic function, the great god see words. Guidance is very welcome.

Get method

Axios.get (URL, {
Params: {' key ': ' Value '}
}). Then (function (response) {
Alert ('. Concat (Response.data, ' \ r \ n ', Response.Status, ' \ r \ n ', Response.statustext, ' \ r \ n ', response.headers, ' \ r \ n ' , Response.config));
}). catch (function (error) {
alert (error);
});

Get data on the server side

Const Urlmodule = require (' URL ');Let params = Urlmodule.parse (Request.url, true). Query; //Parse data to get JSON object Let value = Params.key; //Get parameter values by parameter name

Post method

var params = new Urlsearchparams ();
Params.append (' key ', ' value ');
Axios.post (URL, params). Then ( Function (response) {
alert (' . Concat (Response.data, ' \ r \ n ', Response.Status, ' \ r \ n ', Response.statustext, ' \ r \ n ', response.headers, ' \ r \ n ', Response.config));
}). catch (function (error) {
alert (error);
});

Get data on the server side

Const Querystringmodule = require (' querystring ');Let postdata = ";request.on (' Data ', function (chunk) {PostData + = chunk; //Receive data });Let params = Querystringmodule.parse (postdata); //Parse data to get JSON object Let value = Params.key; //Get parameter values by parameter name

This kind of writing speculation should be just a relatively simple implementation, hoping to help others, but also hope that master advice;

The Get,post method of Axios

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.