700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > js 即时上传php_php+js实现异步图片上传实例分享

js 即时上传php_php+js实现异步图片上传实例分享

时间:2020-06-29 19:39:23

相关推荐

js 即时上传php_php+js实现异步图片上传实例分享

Html5 Ajax 上传文件

var xhr;

function createXMLHttpRequest()

{

if(window.ActiveXObject)

{

xhr = new ActiveXObject("Microsoft.XMLHTTP");

}

else if(window.XMLHttpRequest)

{

xhr = new XMLHttpRequest();

}

}

function UpladFile()

{

var fileObj = document.getElementById("file").files[0];

var FileController = 'upload.php';

var form = new FormData();

form.append("myfile", fileObj);

createXMLHttpRequest();

xhr.onreadystatechange = handleStateChange;

xhr.open("post", FileController, true);

xhr.send(form);

}

function handleStateChange()

{

if(xhr.readyState == 4)

{

if (xhr.status == 200 || xhr.status == 0)

{

var result = xhr.responseText;

var json = eval("(" + result + ")");

alert('图片链接:\n'+json.file);

}

}

}

.txt{ height:28px; border:1px solid #cdcdcd; width:670px;}

.mybtn{ background-color:#FFF; line-height:14px;vertical-align:middle;border:1px solid #CDCDCD;height:30px; width:70px;}

.file{ position:absolute; top:0; right:80px; height:24px; filter:alpha(opacity:0);opacity: 0;width:260px }

图片

浏览...

上传

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。