Ajax的HTML表单的enctype [英] html form enctype on ajax
问题描述
我有这个jQuery code表示提交表单数据的:
i have this jquery code that submits my form data:
<script type="text/javascript">
$(document).ready(function(){
$("#message").hide();
$("#please_wait_box").hide();
$("#viewreseller").submit(function(e){
e.preventDefault();
dataString=$("#viewreseller").serialize();
$.ajax({
type: "POST",
url: "view_reseller-go.php",
cache: false,
data: dataString,
success: function(res){
//$("#message").show();
$("#please_wait_box").hide();
$("#message").html(res);
$('#message').fadeIn('slow');
if(res.indexOf("success")!=-1)
{
window.location.href = res.substr(8);
}
}
});
});
});
</script>
我需要设置的加密类型的形式的multipart / form-data的对
- 这可能与我上面的code?
i need to set the enctype on the form to multipart/form-data
- is this possible with my above code?
推荐答案
由于您使用Ajax提交表单数据,设置加密类型
将没有任何效果。您完全绕开了表单提交过程中,将使用它。
Since you are using Ajax to submit the form data, setting the enctype
will have no effect. You are completely bypassing the form submission process that would use it.
那么,让我们来问你是否能适应了code具有相同的效果设置加密类型
。该属性对表单提交三种效果。
So, let's ask if you can adapt that code to have the same effect as setting the enctype
. The attribute has three effects on a form submission.
- 它集内容类型的HTTP POST请求。您可以轻松地做到这一点。
标题:{内容类型:多部分/表单数据}
- 在它的连接codeS使用表单中的数据
的multipart / form-data的
而不是应用程序/ x-WWW的形式urlen codeD
-连载
将永远不会做到这一点 - 这将包括文件从文件中输入 -
连载
将永远不会做到这一点
- It sets the content-type of the HTTP post request. You can do this easily.
headers: { "Content-Type": "multipart/form-data" }
- It encodes the data in the form using
multipart/form-data
instead ofapplication/x-www-form-urlencoded"
-serialize
will never do this - It will include files from file inputs -
serialize
will never do this
jQuery有没有建在通过Ajax来处理文件上传。 <一href="https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications#Example.3A_Uploading_a_user-selected_file"相对=nofollow> MDN有过程的使用内置的浏览器的API (请注意,你需要一个现代的浏览器,支持一些这些API的)。
jQuery has nothing built in to handle file uploads via Ajax. MDN has a pretty detailed description of the process for using built in browser APIs (note that you need a modern browser to support some of those APIs).
由于您使用jQuery,你应该看看使用支持Ajax的文件上传一个pre-写库。有很多它们可,但我不能推荐一个具体的问题。
Since you are using jQuery, you should probably look at using a pre-written library which supports Ajax file uploads. There are plenty of them available, but I can't recommend a specific one.
这篇关于Ajax的HTML表单的enctype的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!