使用JavaScript控制后,请使用Appengine Python提交文件



我正在尝试对输入文件进行简单的检查。使用JavaScript通过表格发送,并在Python运行时和使用Jinja2中使用App Engine发送。表格如下:

<form action="{{ upload_url|safe }}" name="inputfile" id="inputfile" method="post" enctype="multipart/form-data">
    Load a file:
    <input type="file" id="file" name="file"><br>
    <input type="button" name="submit" value="Send" onclick="checkForm()">
</form></br>

checkform()函数如下:

function checkForm(){
var message ="";
if(!document.inputfile.file.value) message += "You must select a filen";
if(document.inputfile.file.value && !(estensione(document.inputfile.file.value))) message += "The extension of the file MUST be .txtn";
if(message != "" ) alert(message);
else document.inputfile.submit();   
}

当我尝试提交没有文件或未提交txt文件时,警报消息没有问题。但是,当正确的情况下,函数不会提交文件。如果我使用提交输入而不是按钮,则将文件发送毫无问题。有人知道怎么了?

我认为输入名称是引起此问题的。我尝试了没有名称的代码,它起作用了。删除名称字段后可以尝试代码吗?

<input type="button" value="Send" onclick="checkForm()">

最新更新