0

I'm trying to upload a file to one of my localhost folders using reactjs and jquery, when i submit a file it works fine with no errors but when i go to the folder to check i find nothing there (nothing in my folder)

uploadFile()
    {
      var data = new FormData();    
      data.append('file', this.refs.file.getDOMNode().files[0]);
        $.ajax({
            url: 'http://localhost:8080/files/uploads',
            data: data,
            processData: false,
            contentType: false,
            type: 'POST',
            cache: false,
            success: function(data){
                alert("File uploaded");     
            },
            error: function()
            {             
              alert("Error . . .");
            }
        });
    }




render: function()
    {

        return(  <form style={{width:100+'%'}} encType="multipart/form-data">
                    <div className="col-sm-12 padding-left-0 padding-right-0">
                        <input ref="file" type="file" name="file" id="filer_input2"> </input>
                        <input type="button" value ="submit" onClick={this.uploadFile}/>
                    </div>
                </form>);
    }

any idea about this issue please ?

1 Answers1

0

You need to use here redux-thunk for this kind of asynchronous operations.

Here you can see a full example on how to create an ajax request using react and jquery

Tal Avissar
  • 10,088
  • 6
  • 45
  • 70