我在网上搜索,发现了很多 jQuery 和 iframe 的解决方案。
谁能给我解决方案如何在不使用 jQuery、iframes 或 flash 的情况下为 IE7/8 制作 AJAX 文件 uploader ?
这是我的 HTML 脚本
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-type' content='text/html; charset=utf-8'>
<title>Ajax Uploader</title>
<script>
function iajax()
{
oField=document.myform.myfile;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('eds').innerHTML=xmlhttp.responseText;
}
};
xmlhttp.setRequestHeader("Content-Type", "multipart/form-data");
xmlhttp.open("post","file.php",true);
xmlhttp.send();
}
</script>
</head>
<body>
<form name='myform' enctype="multipart/form-data" method="post" onsubmit="iajax(this)">
<input type="file" name="myfile" />
<button type="submit">Upload file to the server</button>
</form>
<div id='eds'></div>
</body>
</html>
我的 PHP 脚本:
<?php
$name=$_FILES['myfile']['name'];
$type=$_FILES['myfile']['type'];
$size=$_FILES['myfile']['size'];
$temp_name=$_FILES['myfile']['tmp_name'];
if(!move_uploaded_file($_FILES['myfile']['tmp_name'], './public/'.$name))
{
echo "Image Uploading Error";
}
else
{
echo "Upload Image Name : ".$name;
}
?>
最佳答案
到目前为止,我所知道的所有最新浏览器都不可能,如果您希望浏览器不刷新,则没有 iframe 就无法将文件发送到服务器,即使是众所周知的 js 框架和插件也使用 iframe 。不确定闪光灯是如何做到这一点的,但唯一的可能性是
- 要么不要使用ajax
- 否则使用您不想使用的上述选项之一
关于javascript - 如何在没有 jQuery、iframes 或 flash 的情况下为 IE7/8 制作 AJAX 文件 uploader ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19333282/