我有一个dijit表单,它上传一个excel文件,并通过post将其发送到upload.php,upload.php会将此文件的数据加载到数据库。我的问题是文件没有发送。我使用dojo 1.10。
我试过xhrPost和iframe,但没有成功,我不知道如何做,我应该发送什么类型的数据(是文本吗?)
<head>
<link rel="stylesheet" href="./dojoroot/dijit/themes/claro/claro.css">
<script>dojoConfig = {parseOnLoad: true}</script>
<script src='./dojoroot/dojo/dojo.js'></script>
<script>
require(["dojo/parser", "dijit/form/Form", "dijit/form/Button", "dojox/form/Uploader", "dojox/form/uploader/plugins/IFrame","dojox/form/uploader/FileList", "dojo/request/iframe", "dojo/domReady!"]);
function sendForm(){
var form = dojo.byId("uploadForm");
dojo.connect(form, "onsubmit", function(event){
dojo.stopEvent(event);
var xhrArgs = {
form: dojo.byId("uploadForm"),
handleAs: "text",
load: function(data){
dojo.byId("response").innerHTML = "Form posted.";
},
error: function(error){
dojo.byId("response").innerHTML = "Form posted.";
}
}
dojo.byId("response").innerHTML = "Form being sent..."
var deferred = dojo.xhrPost(xhrArgs);
});
}
dojo.ready(sendForm);
</script>
</head>
<div data-dojo-type="dijit/form/Form" id="uploadForm" action="upload.php" method="post" name="upload_excel" enctype="multipart/form-data">
<div>
<input data-dojo-type="dojox/form/Uploader" name="file" multiple="false" type="file" id="file" label="Browse" data-dojo-props="name:'file',showInput:'before',isDebug:true">
<input type="submit" id="submit" label="Upload" name="Import" dojoType="dijit/form/Button" />
<div id="files2" dojoType="dojox/form/uploader/FileList" uploaderId="file"></div>
</div>
</div>
在upload.php我有这个:
if(isset($_POST["Import"])){
$filename = $_FILES["file"]["tmp_name"];
....
我读了dojo文档,但是我不知道如何解决我的问题。我感谢你的帮助。
1条答案
按热度按时间3duebb1j1#
表单内部有一个错误。名为
import
的input标记实际上是一个按钮,当您将其发送到服务器时,它将没有值。因此isset($_POST["Import"])
将返回false。所以去掉这张支票就可以了。