主頁(yè) > 知識(shí)庫(kù) > 一個(gè)簡(jiǎn)單的ajax上傳進(jìn)度顯示示例

一個(gè)簡(jiǎn)單的ajax上傳進(jìn)度顯示示例

熱門標(biāo)簽:銀行業(yè)務(wù) Linux服務(wù)器 服務(wù)器配置 電子圍欄 阿里云 團(tuán)購(gòu)網(wǎng)站 Mysql連接數(shù)設(shè)置 科大訊飛語(yǔ)音識(shí)別系統(tǒng)
本例用了jquery.form.js請(qǐng)到演示頁(yè)面查看
 
CSS Code
復(fù)制代碼 代碼如下:

style>
form { display: block; margin: 20px auto; background: #eee; border-radius: 10px; padding: 15px }
#progress { position:relative; width:400px; border: 1px solid #ddd; padding: 1px; border-radius: 3px; }
#bar { background-color: #B4F5B4; width:0%; height:20px; border-radius: 3px; }
#percent { position:absolute; display:inline-block; top:3px; left:48%; }
/style>

XML/HTML Code
復(fù)制代碼 代碼如下:

form id="myForm" action="upload.php" method="post" enctype="multipart/form-data">
input type="file" size="60" name="myfile">
input type="submit" value="Ajax File Upload">
/form>
div id="progress">
div id="bar">/div>
div id="percent">0%/div >
/div>
div id="message">/div>

JavaScript Code
復(fù)制代碼 代碼如下:

script>
$(document).ready(function()
{
var options = {
beforeSend: function()
{
$("#progress").show();
//clear everything
$("#bar").width('0%');
$("#message").html("");
$("#percent").html("0%");
},
uploadProgress: function(event, position, total, percentComplete)
{
$("#bar").width(percentComplete+'%');
$("#percent").html(percentComplete+'%');
},
success: function()
{
$("#bar").width('100%');
$("#percent").html('100%');
},
complete: function(response)
{
$("#message").html("font color='green'>"+response.responseText+"/font>");
},
error: function()
{
$("#message").html("font color='red'> ERROR: unable to upload files/font>");
}
};
$("#myForm").ajaxForm(options);
});
/script>

upload.php
復(fù)制代碼 代碼如下:

?php
$output_dir = "../upload/";
if(isset($_FILES["myfile"]))
{
//Filter the file types , if you want.
if ($_FILES["myfile"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "br>";
}
else
{
//move the uploaded file to uploads folder;
move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir. $_FILES["myfile"]["name"]);
echo "Uploaded File :".$_FILES["myfile"]["name"];
}
}
?>
您可能感興趣的文章:
  • AJAX和JSP實(shí)現(xiàn)的基于WEB的文件上傳的進(jìn)度控制代碼
  • AJAX 進(jìn)度條實(shí)現(xiàn)代碼
  • ajax+php打造進(jìn)度條 readyState各狀態(tài)
  • ajax+php打造進(jìn)度條代碼[readyState各狀態(tài)說(shuō)明]
  • 讓ajax更加友好的實(shí)現(xiàn)方法(實(shí)時(shí)顯示后臺(tái)處理進(jìn)度。)
  • ajax提交加載進(jìn)度條示例代碼
  • php+ajax實(shí)現(xiàn)帶進(jìn)度條的大數(shù)據(jù)排隊(duì)導(dǎo)出思路以及源碼
  • jquery+php+ajax顯示上傳進(jìn)度的多圖片上傳并生成縮略圖代碼
  • jsp+ajax發(fā)送GET請(qǐng)求的方法
  • jquery+ajax實(shí)現(xiàn)跨域請(qǐng)求的方法
  • asp.net+ajax的Post請(qǐng)求實(shí)例
  • 服務(wù)端配置實(shí)現(xiàn)AJAX跨域請(qǐng)求
  • 解決ajax跨域請(qǐng)求數(shù)據(jù)cookie丟失問(wèn)題
  • django通過(guò)ajax發(fā)起請(qǐng)求返回JSON格式數(shù)據(jù)的方法
  • Ajax在請(qǐng)求過(guò)程中顯示進(jìn)度的簡(jiǎn)單實(shí)現(xiàn)

標(biāo)簽:大理 廣元 萍鄉(xiāng) 江蘇 蚌埠 衡水 棗莊 衢州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《一個(gè)簡(jiǎn)單的ajax上傳進(jìn)度顯示示例》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266