Extjs 使用ajax上传文件,解决Object #<HTMLDivElement> has no method 'submit'

来源:互联网 发布:淘宝购物车不能用 编辑:程序博客网 时间:2024/06/03 05:26
1、使用isUpload上传文件,并不是通过XMLHttpRequests进行上传的,extjs的实现原理是通过隐藏的iframe进行提交。
     ExtJs通过强大的内部封装,使ajax请求看起来可以直接提交二进制流数据。每当提交文件数据时,ExtJs会自动创建iframe,在iframe中提交。提交完成      后又自动移去,一切显得天衣无缝。
2、前台js代码,跟普通ajax就多了,form:"form表单ID" ,isUpload: true
<h1>Ajax文件上传</h1> <div class="content" id="div2"> <form id="form1"> 请选择文本文件:<input type="file" name="file" /> <input type="button" id="button1" value="上传" /> </form> </div>
//文件上传 Ext.get("button1").on("click", function () {     Ext.Ajax.request({         url: "Ajax_FileUp",         isUpload: true,         form: "form1",         success: function (response) {             Ext.MessageBox.alert("上传成功,文本文件内容:", response.responseText);         }     }); });

注意ajax中配置的form,必须是html中存在的form的id,而不是Ext.form.Panel的id
 var form1=Ext.create('Ext.form.Panel',{
        id:'form1',