Images uploaded by Express under NodeJS cannot get the returned data before demo

  node.js, question

The front-end code is as follows:

<!  DOCTYPE html>
 <html lang="zh-CN">
 <meta charset="utf-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 < title > < percentage = title percentage > < /title >
 <!  -- Bootstrap -->
 <link rel="stylesheet" href="//">
 <link href="/stylesheets/fileinput.min.css" rel="stylesheet">
 <!  --[if lt IE 9]>
 <script src="//"></script>
 <script src="//"></script>
 <!  [endif]-->
 <!  -subject->
 <div class="container">
 <div class="row">
 <div class="col-md-12">
 <label class="control-label">Planets and Satellites</label>
 <input id="carouselUpload" name="carouselUpload" type="file" data-show-preview="false" multiple class="file-loading">
 <!  -- jQuery Loading -->
 <script src="//"></script>
 <!  -- Bootstrap JS Loading -->
 <script src="//"></script>
 <!  -- fileupload JS Loading -->
 <script src="/javascripts/fileinput.min.js"></script>
 <script src="/javascripts/fileinput_locale_zh.js"></script>
 <!  -- bootstrap fileinput config and callback function -->
 $(document).on('ready', function() {
 language: "zh",
 uploadUrl: "",
 allowedFileExtensions: ["jpg", "png", "gif", "jpeg"],
 uploadAsync: true
 $('#carouselUpload').on('fileuploaded', function(event, numFiles, label) {


var express = require('express');
 var router = express.Router();
 var formidable = require('formidable');
 var fs = require('fs');
 /* GET home page. */
 router.get('/', function(req, res, next) {
 res.render('index', { title: 'Express' });
 });'/', function(req, res, next) {
 res.header( 'Content-Type','text/javascript;  charset=utf-8');  //Set the return string encoding
 var form = new formidable.IncomingForm();  //Create Object
 form.uploadDir = "./public/images/uploads/";  //Set the path where temporary files are stored
 form.encoding='utf-8';  //Set the encoding of uploaded data
 form.keepExtensions = true;  //Set whether to keep the extension name of uploaded files
 form.maxFieldsSize = 2 * 1024 * 1024;  //File Size
 form.parse(req, function(err, fields, files) {
 if (err) {
 res.render('index', { title: err });
 var extName = '';  //Filename extension
 switch (files.carouselUpload.type) {
 case 'image/pjpeg':
 extName = 'jpg';
 case 'image/jpeg':
 extName = 'jpg';
 case 'image/png':
 extName = 'png';
 case 'image/x-png':
 extName = 'png';
 case 'image/gif':
 extName = 'gif';
 if(extName.length == 0){
 Res.send ('Error in Uploading File Type!'  );
 Parse (newdate ()) plus'.' plus extName;
 Uploaddir plus avatarName;
 fs.renameSync(files.carouselUpload.path, newPath);  //Rename
 module.exports = router;

Upload can be completed normally without any error prompt. You can also see the return information from chrome’s inside. The return of the finally bound fileuploaded Event to inside can never get anything. However, it is strange that if this event is change, it can be triggered normally!

The problem has been solved. The original server res.send (return data) inside, the front-end FILENPUT can only process json format results, and in PHP inside json_encode is also used to wrap the returned data. Now the node end can trigger FILENPUT’s fileuploaded event by making the string result into json format returns.