如何使用jquery以常规形式传递文件
我得到了这个代码,我需要将 $_FILES 从 /form form page/ 传递到 mail.php 没有通过这种类型的jquery,有人吗?
function send(datastr){
$.ajax({
type: "POST",
url: "mail.php",
data: datastr,
cache: false,
success: function(html){
$("#risposta").fadeIn("slow");
$("#risposta").css("padding","20px");
$("#risposta").css("height","auto");
$("#risposta").css("border","1px solid #c98b18");
$("#risposta").html(html);
setTimeout('$("#risposta").fadeOut("slow")',2000);
}
});
}
I got this code, i would need to pass $_FILES to mail.php from /form form page/
is not passed with this type of jquery, anyone ?
function send(datastr){
$.ajax({
type: "POST",
url: "mail.php",
data: datastr,
cache: false,
success: function(html){
$("#risposta").fadeIn("slow");
$("#risposta").css("padding","20px");
$("#risposta").css("height","auto");
$("#risposta").css("border","1px solid #c98b18");
$("#risposta").html(html);
setTimeout('$("#risposta").fadeOut("slow")',2000);
}
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还没有找到使用 AJAX 来做到这一点的方法。 ATM,您必须即时生成表格。唯一的问题是用户必须选择您要上传的文件,然后您可以从那里继续自动化。
I've yet to see a way to do this with AJAX. ATM, you will have to generate a form on-the-fly. The only problem with that is the user will have to select the file that you want to upload, and then from there you can continue automation.
我相信你不能这样做,因为 ajax 没有对服务器文件系统的操作访问权限。它只能从服务器加载数据,但无法操作服务器端的文件(我想,我想我在某处读过)。
不过,您可以使用隐藏的 iframe 来伪造它。当您提交表单时,信息将发送到操作服务器文件系统的 iframe。这是教程:http://www.openjs.com/articles/ajax/ajax_file_upload/
您会注意到,当您提交表单时,页面确实加载了更多数据,但页面本身并未重新加载。
还有一些插件。最知名的是 jQuery 表单插件。
I believe you cannot do this because ajax has no manipulation access to the files system of the server. It can only load data from server but can't manipulate the files in the server side (I guess, I think I read that somewhere).
However you can fake it using a hidden iframe. When you submit the form the information goes to the iframe which manipulate the files system of the server. Here's the tutorial: http://www.openjs.com/articles/ajax/ajax_file_upload/
You will notice that the page does load more data when you submit the form, but the page itself isn't reloaded.
There are also some plugins. The most known is jQuery Form Plugin.