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