Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery在reactjs中上载文件_Jquery_Reactjs - Fatal编程技术网

使用jquery在reactjs中上载文件

使用jquery在reactjs中上载文件,jquery,reactjs,Jquery,Reactjs,我正在尝试使用reactjs和jquery将文件上载到我的一个localhost文件夹中,当我提交文件时,它可以正常工作,没有错误,但是当我转到文件夹检查时,我发现那里没有任何内容(我的文件夹中没有任何内容) uploadFile() { var data=new FormData(); data.append('file',this.refs.file.getDOMNode().files[0]); $.ajax({ 网址:'http://localhost:8080/files/upload

我正在尝试使用reactjs和jquery将文件上载到我的一个localhost文件夹中,当我提交文件时,它可以正常工作,没有错误,但是当我转到文件夹检查时,我发现那里没有任何内容(我的文件夹中没有任何内容)

uploadFile()
{
var data=new FormData();
data.append('file',this.refs.file.getDOMNode().files[0]);
$.ajax({
网址:'http://localhost:8080/files/uploads',
数据:数据,
processData:false,
contentType:false,
键入:“POST”,
cache:false,
成功:功能(数据){
警报(“上传文件”);
},
错误:函数()
{             
警报(“错误…”);
}
});
}
render:function()
{
报税表(
);
}
关于这个问题有什么想法吗?

对于这种异步操作,您需要使用redux thunk


您可以看到一个关于如何使用react和jquery创建ajax请求的完整示例,上传的服务器代码在哪里?您不需要jquery。试试
fetch
。好的,伙计们,非常感谢。
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>);
    }