【问题标题】:Simple form submit with files带文件的简单表单提交
【发布时间】:2014-02-18 15:02:06
【问题描述】:

我正在尝试使用 React JS 编写一个带有输入文件类型的简单上传表单。当我提交文件时,它没有提交多表单数据。它正在提交纯输入文件名。

如果我们想在 React 中编写上传功能,是否需要进行任何其他更改。

上传的基本javascript代码(js fiddle link):

    /** @jsx React.DOM */
var HelloMessage = React.createClass({
  render: function() {
    return (<div>

                <form name="secret" ENCTYPE="multipart/form-data"  method="POST" action="http://localhost:8080/uploadFile">
            Please choose two files to upload.
            <br/>
                File 1:<input type="file" id="profilePic" name="profilePic"/>             
            <br/> 
                <input type="submit" value="submit"/>
    </form>
            </div>);
  }
});

React.renderComponent(<HelloMessage />, document.body);

谁能帮我用 React JS 写代码。

【问题讨论】:

  • 您发布的是 HTML,而不是 JavaScript。
  • @AnthonyGrist 我给出了实际的 React JS 代码。你能看看这个吗

标签: javascript html forms reactjs


【解决方案1】:

大小写对于 React 组件很重要。试试encType 而不是ENCTYPE。 (您应该在控制台中看到一条警告,建议您使用encType。)

这是标签和属性的完整列表:DOM Elements

【讨论】:

  • 谢谢。它解决了我的问题
猜你喜欢
  • 1970-01-01
  • 2013-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-21
  • 2013-01-04
  • 2016-02-04
  • 2017-09-15
相关资源
最近更新 更多