码迷,mamicode.com
首页 > Web开发 > 详细

文件上传

时间:2016-03-18 23:32:25      阅读:372      评论:0      收藏:0      [点我收藏+]

标签:

使用FormData提交表单及上传文件:
[html] view plain copy
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  
<html>  
 <head>  
  <meta http-equiv="content-type" content="text/html; charset=utf-8">  
  <title> FormData Demo </title>  
  <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>  
  
  <script type="text/javascript">  
  <!--  
    function fsubmit(){  
        var data = new FormData($(‘#form1‘)[0]);  
        $.ajax({  
            url: ‘server.php‘,  
            type: ‘POST‘,  
            data: data,  
            dataType: ‘JSON‘,  
            cache: false,  
            processData: false,  
            contentType: false  
        }).done(function(ret){  
            if(ret[‘isSuccess‘]){  
                var result = ‘‘;  
                result += ‘name=‘ + ret[‘name‘] + ‘<br>‘;  
                result += ‘gender=‘ + ret[‘gender‘] + ‘<br>‘;  
                result += ‘<img src="‘ + ret[‘photo‘]  + ‘" width="100">‘;  
                $(‘#result‘).html(result);  
            }else{  
                alert(‘提交失敗‘);  
            }  
        });  
        return false;  
    }  
  -->  
  </script>  
  
 </head>  
  
 <body>  
    <form name="form1" id="form1">  
        <p>name:<input type="text" name="name" ></p>  
        <p>gender:<input type="radio" name="gender" value="1">male <input type="radio" name="gender" value="2">female</p>  
        <p>photo:<input type="file" name="photo" id="photo"></p>  
        <p><input type="button" name="b1" value="submit" onclick="fsubmit()"></p>  
    </form>  
    <div id="result"></div>  
 </body>  
</html>  

http://blog.csdn.net/fdipzone/article/details/38910553

文件上传

标签:

原文地址:http://www.cnblogs.com/obeing/p/5293939.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!