问题描述
我正在尝试使用jqgrid(在Zend Framework项目中)实现文件上传. jqgrid允许您创建文件"类型的输入字段,但不启用ENCTYPE ="multipart/form-data".
I am trying to implement file upload with jqgrid (in a Zend Framework project). jqgrid allows you to create an input field of type "file" but does not enable ENCTYPE="multipart/form-data".
创建者建议使用其他插件来处理文件上传,特别是 Ajax文件上传.他说要使用onInitializeForm()
方法初始化它,但确切的方法对我来说还不清楚.他说,
The creator recommends using another plugin to handle file uploads, specifically Ajax File Upload. He says to initialize it using the onInitializeForm()
method but exactly how to do this is not clear to me. He says,
这就是有关如何执行此操作的说明.
And that is about it for instructions on how to do this.
我到目前为止所做的事情:我有显示文件输入字段的jqgrid编辑表单,并且所有适当的插件文件都已安装到位并正确加载.我无法确定的是如何获取提交的表单以正确地上传文件(我想我无法弄清楚如何使用onInitializeForm事件初始化ajax文件上传插件").任何想法都将不胜感激.
What I have done so far:I have the jqgrid edit form displaying the file input field and I have all of the various plugin files in place and loading properly. What I cannot figure out is how to get the submitted form to properly upload the file (I guess I can't figure out how to "initialize the ajax file upload plugin with the onInitializeForm event"). Any ideas are greatly appreciated.
对于什么值,我可以启动InitializeForm来触发诸如alert('test')之类的简单事件,但是每次加载网格时它都会触发越来越多的数字(例如,第一次没有触发,下次加载网格时触发一个警报).网格,下次有两个警报,依此类推.)
For what it is worth I can get onInitializeForm to trigger something simple like alert('test') but it triggers in growing numbers each time you load the grid (like, nothing first time, one alert the next time you load the grid, two alerts the next time, etc).
推荐答案
答案如下:
<!-- Add your other js files like jQuery, jqGrid etc. -->
<script type="text/javascript" src="js/ajaxfileupload.js"></script>
<script language="javascript">
$(function() {
$(document).ready(function() {
jQuery("#your_grid_id").jqGrid({
url: 'your_url',
datatype: 'json',
mtype: 'post',
pager: 'your_pager_id',
colNames: ["Description", "File"],
colModel: [{name: "desc", index: "desc", ... ... ...}, {name: "file_to_upload", index: "file_to_upload", edittype: "file", ... ... ...}]
}).navGrid("#your_pager_id",{{... ... ...},{
jqModal:true,closeAfterEdit: true,recreateForm:true,onInitializeForm : function(formid){
$(formid).attr('method','POST');
$(formid).attr('action','');
$(formid).attr('enctype','multipart/form-data');
}, afterSubmit : function(response, postdata){
$.ajaxFileUpload({
url: 'your_file_url_where_upload_operates',
secureuri:false,
fileElementId:'file_to_upload',
dataType: 'json',
success: function (data, status) {
alert("Upload Complete.");
}
});
}
}},{
jqModal:true,closeAfterAdd: true,recreateForm:true,onInitializeForm : function(formid){
$(formid).attr('method','POST');
$(formid).attr('action','');
$(formid).attr('enctype','multipart/form-data');
}, afterSubmit : function(response, postdata){
$.ajaxFileUpload({
url: 'your_file_url_where_upload_operates',
secureuri:false,
fileElementId:'file_to_upload',
dataType: 'json',
success: function (data, status) {
alert("Upload Complete.");
}
});
}
}
});
});
});
</script>
我使用recreateForm: true
来确保在每次添加或编辑表单时都重新创建该表单.
I used recreateForm: true
to ensure that on every Add or Edit the form is re-created.
如果您有问题,请随时问我.
If you have problem yet, please feel free to ask me.
这篇关于在PHP中使用jqgrid上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!