欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用jquery+iframe做一個(gè)ajax上傳效果(實(shí)例)

 更新時(shí)間:2017年08月24日 10:04:41   投稿:jingxian  
下面小編就為大家?guī)?lái)一篇使用jquery+iframe做一個(gè)ajax上傳效果(實(shí)例)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

html頁(yè)面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>利用jquery+iframe做一個(gè)ajax上傳效果</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<script src="http://libs.baidu.com/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
// 利用 jquery+iframe 做一個(gè)ajax上傳效果

/*
思路:
1: 點(diǎn)擊"提交"時(shí)的瞬間,生成一個(gè)iframe對(duì)象,插入body中
2: 修改form的target ,為iframe的name值
3: 給iframe加1個(gè)事件 ,onload
*/

$(
 function() {
  $('input:button').click(function(){
   //alert('s');
   var ifmname = 'ifm' + Math.random();
   var ifm = $('<iframe width="0" height="0" frameborder="0" name="'+ ifmname +'">');
   ifm.appendTo($('body'));

   $('form').attr('target',ifmname);
   $('form').submit();

   $('#progress').html('<img src="<img src="http://img.jbzj.com/file_images/article/201708/loading.gif" alt="" />" border="0">');
   ifm.load(function(){
    $('#progress').html('上傳完畢');
    this.remove();
   });

  }); 
 }
);


</script>
<style type="text/css">
</style>
</head>
 <body>
  <div id="progress"></div>
  <form action="upfile.php" method="post" enctype="multipart/form-data" target="upfile">
   <input type="file" name="pic" /><br />
   <input type="button" value="提交" />
  </form>  
 </body>
</html>

upfile.php

 echo move_uploaded_file($_FILES['pic']['tmp_name'],'./upload/' . $_FILES['pic']['name']) ? 'OK':'fail';

以上這篇使用jquery+iframe做一個(gè)ajax上傳效果(實(shí)例)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論