一個(gè)偽ajax圖片上傳代碼實(shí)現(xiàn)示例
更新時(shí)間:2014年03月17日 16:44:46 作者:
這篇文章主要介紹了自己寫(xiě)的一個(gè)偽ajax圖片上傳實(shí)現(xiàn)代碼,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
<?php
if($_FILES){
?>
<script>
window.parent.ajaxUploadPicture.uploadCallback('http://img0.bdstatic.com/img/image/5099213b07eca8065380ce7f75e95dda144ad348269.jpg');
</script>
<?php
die;
}
?>
<!DOCTYPE html>
<html>
<head>
<script>
ajaxUploadPicture = { $o1:'' };
ajaxUploadPicture.ajaxUploadFile = function ($o){
this.$o1 = $o;
var $iframe = document.createElement('iframe');
$iframe.style.display = 'none';
$iframe.name = 'iframe';
$iframe.id = 'iframe';
document.body.appendChild($iframe);
var $form = document.createElement("form");
$form.method = "post";
$form.enctype = "multipart/form-data";
$form.action = "";
$form.target = 'iframe';
$newO = $o.cloneNode();
$form.appendChild($newO);
$form.submit();
}
ajaxUploadPicture.uploadCallback = function ($url){
$pic = document.createElement('img');
$pic.width = "200";
$pic.height = "150";
$pic.src = $url;
if(document.getElementById('picshow') == null){
$div = document.createElement("div");
$div.id = 'picshow';
this.$o1.parentNode.insertBefore($div,this.$o1.nextSibling);
}else{
$div = document.getElementById('picshow');
}
$div.innerHTML = '';
$div.appendChild($pic);
};
</script>
</head>
<body>
<input type="file" name="file" onchange = "ajaxUploadPicture.ajaxUploadFile(this);">
</body>
</html>
面向?qū)ο笏枷?,form提交到一個(gè)隱藏的iframe,執(zhí)行回調(diào)js函數(shù)。實(shí)現(xiàn)圖片回顯。后臺(tái)php的功能沒(méi)有完善。
您可能感興趣的文章:
- php ajax無(wú)刷新上傳圖片實(shí)例代碼
- Javascript異步表單提交,圖片上傳,兼容異步模擬ajax技術(shù)
- Jquery ajaxsubmit上傳圖片實(shí)現(xiàn)代碼
- JQuery+ajax實(shí)現(xiàn)批量上傳圖片(自寫(xiě))
- jquery的ajaxSubmit()異步上傳圖片并保存表單數(shù)據(jù)演示代碼
- swfupload ajax無(wú)刷新上傳圖片實(shí)例代碼
- php+ajax實(shí)現(xiàn)圖片文件上傳功能實(shí)例
- 自己動(dòng)手打造ajax圖片上傳(網(wǎng)上沒(méi)有的)
- jquery+php+ajax顯示上傳進(jìn)度的多圖片上傳并生成縮略圖代碼
- PHP+jQuery+Ajax實(shí)現(xiàn)多圖片上傳效果
相關(guān)文章
AJAX驗(yàn)證數(shù)據(jù)庫(kù)內(nèi)容并將值顯示在頁(yè)面
光標(biāo)離開(kāi)文本框,在本頁(yè)面的相應(yīng)地方獲取數(shù)據(jù)庫(kù)中改值所對(duì)應(yīng)的其他數(shù)據(jù),相應(yīng)的實(shí)現(xiàn)代碼如下,感興趣的朋友可以看看2014-08-08Ajax的內(nèi)部實(shí)現(xiàn)機(jī)制、原理與實(shí)踐小結(jié)
AJAX全稱為"Asynchronous JavaScript and XML"(異步JavaScript和XML),Ajax不是一個(gè)技術(shù),它實(shí)際上是幾種技術(shù),每種技術(shù)都有其獨(dú)特這處,合在一起就成了一個(gè)功能強(qiáng)大的新技術(shù)。2010-06-06jquery ajax實(shí)現(xiàn)批量刪除具體思路及代碼
回調(diào)函數(shù),在請(qǐng)求完成后需要進(jìn)行的操作:此處是把選中的checkbox去掉,接下來(lái)為大家詳細(xì)介紹下,感興趣的朋友可以參考下哈,希望對(duì)你有所幫助2013-04-04