茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    原生JS和jQuery版實現(xiàn)文件上傳功能
    來源:易賢網(wǎng) 閱讀:1096 次 日期:2016-07-08 10:12:44
    溫馨提示:易賢網(wǎng)小編為您整理了“原生JS和jQuery版實現(xiàn)文件上傳功能”,方便廣大網(wǎng)友查閱!

    這篇文章主要介紹了HTML5中用js、jQuery結(jié)合Ajax實現(xiàn)文件上傳功能,HTML5中已經(jīng)可以用Ajax上傳文件了,而且代碼簡單,借助 FormData類即可發(fā)送文件數(shù)據(jù),感興趣的小伙伴們可以參考一下

    本文實例分享了原生JS版和jQuery 版實現(xiàn)文件上傳功能的例子,供大家參考,具體內(nèi)容如下

    <!doctype html>

    <html lang="zh">

    <head>

    <meta charset="utf-8">

    <title>HTML5 Ajax Uploader</title>

    <script src="jquery-2.1.1.min.js"></script>

    </head>

    <body>

    <p><input type="file" id="upfile"></p>

    <p><input type="button" id="upJS" value="用原生JS上傳"></p>

    <p><input type="button" id="upJQuery" value="用jQuery上傳"></p>

    <script>

    /*原生JS版*/

    document.getElementById("upJS").onclick = function() {

     /* FormData 是表單數(shù)據(jù)類 */

     var fd = new FormData();

     var ajax = new XMLHttpRequest();

     fd.append("upload", 1);

     /* 把文件添加到表單里 */

     fd.append("upfile", document.getElementById("upfile").files[0]);

     ajax.open("post", "test.php", true);

     ajax.onload = function () {

     console.log(ajax.responseText);

     };

     ajax.send(fd);

    }

    /* jQuery 版 */

    $('#upJQuery').on('click', function() {

     var fd = new FormData();

     fd.append("upload", 1);

     fd.append("upfile", $("#upfile").get(0).files[0]);

     $.ajax({

     url: "test.php",

     type: "POST",

     processData: false,

     contentType: false,

     data: fd,

     success: function(d) {

      console.log(d);

     }

     });

    });

    </script>

    </body>

    </html>

    php代碼:

    <?php

    if (isset($_POST['upload'])) { 

    var_dump($_FILES);

    move_uploaded_file($_FILES['upfile']['tmp_name'], 'up_tmp/'.time().'.dat');

    //header('location: test.php');

    exit;

    }

    ?>

    以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助。

    更多信息請查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機網(wǎng)站地址:原生JS和jQuery版實現(xiàn)文件上傳功能

    2026上岸·考公考編培訓(xùn)報班

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)