2017.12.3 Ajax and react submit data to the specified server program files

Source: Internet
Author: User

varCommon ={test:function (date) {varXhr=NewXMLHttpRequest (); Xhr.onreadystatechange=function () {if(xhr.readystate==4){                if((xhr.status>= $&& xhr.status< -|| xhr.status==304) {alert (xhr.responsetext); }Else{alert ("Request was unsuccessful:"+xhr.status); }}} Xhr.open ("Get","Posttest.js",true); Xhr.setrequestheader ("Content-type","Multipart/form-data") xhr.send (date); alert (date); }};module.exports=common;

Posttest.js content: The equivalent of a server file program, monitoring the front-end request;

varHTTP = require ("http");varurl = require ("URL");varQueryString = require ('QueryString'); Http.createserver (function (request, response) {//request.setencoding (' UTF8 ');Response.writehead ( $, {"Content-type":"Text/plain"}); Response.Write ("Send a piece of data to you! "); Request.addlistener ('Data', function (chunk) {Console.log ('The Post data obtained is:'+Chunk); varName = Querystring.parse (chunk +"'). Name;//Chunk is an object plus an empty string to convert it to a string formatConsole.log ("--------------------");    Console.log (name); }) Response.End ();}). Listen (8888)

3. The input component that resolves the bug gets a value that is empty (that is, object), and only the input component needs to:

View the returned results using:

Console.log (data); Try not to use alert

2017.12.3 Ajax and react submit data to the specified server program files

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.