jQuery - 使用$ .post接收$ _FILES数组 [英] jQuery - receiving the $_FILES array using $.post

查看:181
本文介绍了jQuery - 使用$ .post接收$ _FILES数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过jQuery提交表单。我的表单包含必须上传的字段和文件。它是 ENCTYPE =multipart / form-data



post = $('#myForm')。serialize();
但是,如何获得 $ _ FILES 数组?我需要这个来处理上传的文件。



这可能使用jQuery,如果是这样的话?或者我需要使用特殊的jQuery上传插件?

解决方案

jquery form是最好的方法,
您可以将其添加到任何常规表单中,

 < form method =postaction =URL> 
< input type =filename =file>
< input type =textnametext>
< input type =submit>
< / form>

< script type =text / javascript>
$(document).ready(function(){
$(form).ajaxForm();
})
< / script>

可以按照预期工作,但可以使用ajax。

http://malsup.com/jquery/form/#code-samples


I am attempting to submit a form via jQuery. My form contains fields and a file that must be uploaded. It is of type ENCTYPE="multipart/form-data".

I can receive all my field values using: post = $('#myForm').serialize(); But how do I receive the $_FILES array? I need this to process the uploaded file.

Is this possible using jQuery, and if so how? Or do I need to use a special upload plugin for jQuery?

解决方案

jquery form is the best way to do it, you can add it to any normal form,

<form method="post" action="URL">
<input type="file" name="file">
<input type="text" name"text">
<input type="submit"> 
</form>

<script type="text/javascript">
$(document).ready(function() { 
  $(form).ajaxForm();
})
</script>

will work as expected, but with ajax.

http://malsup.com/jquery/form/#code-samples

这篇关于jQuery - 使用$ .post接收$ _FILES数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆