javascript - File upload component sending two ajax requests -


i'm new react i've cobbled react component different pieces i've found on web. it's supposed upload file via ajax on submit. reason it's double firing. when hit submit server getting 2 requests instead of one.

does stand out react beginner might miss?

/** @jsx react.dom */ var $ = require("jquery") var react = require('react');  var fileform = react.createclass({   getinitialstate: function() {     return {       myfilename: "",       myfilehandle: {}     };   },   handlechange: function(event) {     this.setstate({       files: [event.target.files[0]] // limit 1 file     });   },   handlesubmit: function(e) {     e.preventdefault();      var data = new formdata();     $.each(this.state.files, function(i, file) {       data.append('file-'+i, file)     })      $.ajax({       url: "/api/content/csv/upload.json",       data: data,       cache: false,       contenttype: false,       processdata: false,       type: 'post',       success: function(data) {         this.refs.fileinput.value = null         console.log(this.refs.fileinput)         console.log(data)       }.bind(this),       error: function(xhr, status, err) {         console.log(xhr)         console.log(status)         console.log(err)       }.bind(this)     })    },   render: function() {     return (       <form onsubmit={this.handlesubmit} method="post" enctype="multipart/form-data">         <input ref="fileinput" type="file" onchange={this.handlechange}/>         <input type="submit" value="submit"/>       </form>     )   } })  module.exports = fileform 


Comments