[英]Send data through the Ajax form
I have a form I sent it to every parameter via Ajax But do not send the form data. 我有一个通过Ajax发送给每个参数的表单,但是不发送表单数据。 My question is how should I send the form data via ajax
我的问题是我应该如何通过Ajax发送表单数据
html code : html代码:
<from action="" method="post" enctype="multipart/form-data">
<input type = "file" name = "adrfile" />
<input type = "button" value="Upload" onclick="javascript: upload();" />
</form>
File uploads cannot be done with the XmlHttpRequest object which is traditionally what is considered AJAX. XmlHttpRequest对象无法完成文件上传,XmlHttpRequest对象通常被视为AJAX。 The approach most people take when trying to create and async file upload is to submit the form and target an
iframe
. 大多数人在尝试创建和异步上传文件时采取的方法是提交表单并定位
iframe
。 I would suggest using a javascript library like Uploadify . 我建议使用像Uploadify这样的JavaScript库。
There are many JQuery plugins out there as well that can help you with this. 还有许多JQuery插件可以帮助您解决此问题。 A quick google search should give you many options.
一个快速的谷歌搜索应该给你很多选择。
If you want a headache it can be done for a variety of Browsers - namely latest versions of Firefox, IE, Safari and Opera. 如果您想头疼,可以使用多种浏览器-即Firefox,IE,Safari和Opera的最新版本。
Need code in JS summat like (where obj is the object of the input type="file"
item: 需要JS summat中的代码,例如(其中obj是
input type="file"
项的对象:
function DoReadFile(obj)
{
if (obj.files)
{
// Sensible browers
if (1 == obj.files.length)
{
var file = obj.files[0];
try {
return obj.files[0].getAsBinary();
}
catch (error)
{
// Blank
}
}
}
else
{
// IE
try
{
var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
var fileHandle = fileSystem.OpenTextFile(obj.value, 1);
var contents = contents.ReadAll();
contents.Close();
return contents;
}
catch (error)
{
// Blank
}
}
throw "Cannot read file";
}
You can then get JS to encrypt the data (base 64 etc) and send it along with the other stuff as a post. 然后,您可以获取JS来加密数据(base 64等),并将其与其他内容一起发送。 It cannot be a multi-part form though.
但是,它不能是多部分形式。
But it is a bit of a waste of time. 但这有点浪费时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.