ajaxFileUpload外掛程式

來源:互聯網
上載者:User

標籤:

  • 關鍵詞:

  $.ajaxFileUpLoad();

  data

  status

  dataType

  • 參考資料:

  http://www.cnblogs.com/kissdodog/archive/2012/12/15/2819025.html

  • 第一步:

  先引入jQuery與ajaxFileUpload外掛程式。注意先後順序,這個不用說了,所有的外掛程式都是這樣。 

    <script src="jquery-1.7.1.js" type="text/javascript"></script>    <script src="ajaxfileupload.js" type="text/javascript"></script>
  • 第二步:

  HTML代碼:

<body>    <p><input type="file" id="file1" name="file" /></p>    <input type="button" value="上傳" />    <p><img id="img1" alt="上傳成功啦" src="" /></p></body>
  • 第三步:

  JS代碼

  <script src="jquery-1.7.1.js" type="text/javascript"></script>   <script src="ajaxfileupload.js" type="text/javascript"></script>   <script type="text/javascript">        $(function () {            $(":button").click(function () {                ajaxFileUpload();            })        })        function ajaxFileUpload() {            $.ajaxFileUpload            (                {                    url: ‘/upload.aspx‘, //用於檔案上傳的伺服器端請求地址                    secureuri: false, //是否需要安全性通訊協定,一般設定為false                    fileElementId: ‘file1‘, //檔案上傳域的ID                    dataType: ‘json‘, //傳回值類型 一般設定為json                    success: function (data, status)  //伺服器成功響應處理函數                    {                        $("#img1").attr("src", data.imgurl);                        if (typeof (data.error) != ‘undefined‘) {                            if (data.error != ‘‘) {                                alert(data.error);                            } else {                                alert(data.msg);                            }                        }                    },                    error: function (data, status, e)//伺服器響應失敗處理函數                    {                        alert(e);                    }                }            )            return false;        }    </script>

 

ajaxFileUpload外掛程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.