Ajax上传错误
这个文件索引
<form name="classupload" method="post" enctype="multipart/form-data" action="">
<h3>Select pictures: </h3><br />
<input type="file" name="Filedata[]" style="margin-top:2px;"/><br />
<input type="file" name="Filedata[]" style="margin-top:2px;"/><br />
<input type="file" name="Filedata[]" style="margin-top:2px;"/><br />
<input type="file" name="Filedata[]" style="margin-top:2px;"/><br />
<input type="file" name="Filedata[]" style="margin-top:2px;"/><br />
<div id="viac"></div>
<div style="margin-top:4px;"><a onclick="multiupload();">More</a><br /></div>
<input type="submit" value="Upload" id="classupload"/>
</form>
和文件 javascript
jQuery(document).ready(function() {
$("#classupload").click(function() {
var xleng=document.classupload.elements['Filedata[]'].length;
dv = document.createElement("div");
for (var i = 0; i < xleng ; i++)
{
img=document.classupload.elements['Filedata[]'][i].value;
if(img.toString().length > 1){
$.ajax({
type: "POST",
url: "upload.php",
data: img,
success: function(data_response) {
dv.innerHTML = i + ' - ' + data_response;
}
});
}
}
responseStatus("Done!");
document.getElementById("result").appendChild(dv);
return false; // avoid to execute the actual submit of the form.
})
});
和文件 upload.php
if ($_REQUEST['Filedata']) {
}
请帮我写文件 upload.php 显示文件 因为我什么也没得到,而不是上传文件,请帮忙?
This file index
<form name="classupload" method="post" enctype="multipart/form-data" action="">
<h3>Select pictures: </h3><br />
<input type="file" name="Filedata[]" style="margin-top:2px;"/><br />
<input type="file" name="Filedata[]" style="margin-top:2px;"/><br />
<input type="file" name="Filedata[]" style="margin-top:2px;"/><br />
<input type="file" name="Filedata[]" style="margin-top:2px;"/><br />
<input type="file" name="Filedata[]" style="margin-top:2px;"/><br />
<div id="viac"></div>
<div style="margin-top:4px;"><a onclick="multiupload();">More</a><br /></div>
<input type="submit" value="Upload" id="classupload"/>
</form>
And file javascript
jQuery(document).ready(function() {
$("#classupload").click(function() {
var xleng=document.classupload.elements['Filedata[]'].length;
dv = document.createElement("div");
for (var i = 0; i < xleng ; i++)
{
img=document.classupload.elements['Filedata[]'][i].value;
if(img.toString().length > 1){
$.ajax({
type: "POST",
url: "upload.php",
data: img,
success: function(data_response) {
dv.innerHTML = i + ' - ' + data_response;
}
});
}
}
responseStatus("Done!");
document.getElementById("result").appendChild(dv);
return false; // avoid to execute the actual submit of the form.
})
});
And file upload.php
if ($_REQUEST['Filedata']) {
}
Please help me write file upload.php display file
because Instead of the file being uploaded, I get nothing ,Please HELP ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法直接通过 AJAX 上传文件。您需要一个使用隐藏 Iframe 或利用 HTML5 功能的插件。
You can't upload files via AJAX directly. You need a plug-in that uses a hidden Iframe or makes use of HTML5 features.