Jquery load() + post form (with imagefield)?
Jquery load() + post form (with imagefield)?
我使用load()方法来POST表单并同时加载响应。这样的:
$("#contentdiv").load('upload/', $('#uploadform').serializeArray());
响应可以是在某些子html页面中呈现的数据库实例。它可以是带有错误的相同形式。这就是为什么我们真的想继续使用load()。它可以平滑地处理内建的表单错误,CSRF-token等。
问题是POST当一个字段是一个文件/图像字段。它不工作。
是否有可能加载()+ POST表单时,表单有一个文件字段?也许结合"ajaxSubmit"?
谢谢大家!
你要知道jQuery不提交input=file
你需要使用hidden iframe提交表单,这是一个例子
将attribute
添加到您的表单target="uploadframe"
<script type="text/javascript">
$(function() {
//append hidden iframe
$('body').append('<iframe id="uploadframe" name="uploadframe" style="display:none" />');
//on form submit
$('#bb-upload-form').submit(function(){
//add form action url
$(this).attr('action', 'upload/');
//add form target
$(this).attr('target', 'uploadframe');
//load response from server submited file
iframe = $('#uploadframe').load(function () {
//get response
response = iframe.contents().find('body');
alert(response);
});
});
});
</script>
相关文章:
- Fighting with FRP
- issue with FB.Event.subscribe
- geolocation-marker.js conflict with markerclusterer.js
- Angular 2.0 with JavaScript or TypeScript?
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- WebComponentsJS with IE10
- 指令的模板必须只有一个根元素:With restrict E&替换true
- timeago.js with datatable and PHP
- Ajax and Json with Rails
- errors with Javascript try catch
- how to split a string with ','
- Understanding Javascript scope with "var that = this&qu
- Architecture for CPU intensive tasks with NodeJS & Socke
- How to declare a Map containing certain properties with flow
- 设置'这'在React with Inverse Data Flow中
- Unit-testing multiple use cases with Karma & Mocha.js
- Modify Javascript with C#
- 谷歌地图API v3:Initial View is Fine,but Gray Box with No Map if
- Using jQuery with classes from ES6
- Jquery load() + post form (with imagefield)?