周梦康 发表于 2015-01-27 4348 次浏览 标签 : 跨域上传
https://github.com/blueimp/jQuery-File-Upload/
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>jQuery File Upload Example</title>
</head>
<body>
<input id="fileupload" type="file" name="files" data-url="./index.php" multiple>
<div id="progress" style="height: 30px;background: #bbb;">
    <div class="bar" style="height: 30px;background: #79EA83;width: 20%;"></div>
</div>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="./jquery.ui.widget.js"></script>
<script src="./jquery.iframe-transport.js"></script>
<script src="./jquery.fileupload.js"></script>
<script>
$(function () {
    $('#fileupload').fileupload({
        dataType: 'json',
        add: function (e, data) {
            data.context = $('<button/>').text('Upload')
                .appendTo(document.body)
                .click(function () {
                    data.context = $('<p/>').text('Uploading...').replaceAll($(this));
                    data.submit();
                });
        },
        done: function (e, data) {
            $.each(data.result.files, function (index, file) {
                $('<p/>').text(file.name).appendTo(document.body);
            });
        },
        progressall: function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('#progress .bar').css(
                'width',
                progress + '%'
            );
        }
    });
});
</script>
</body> 
</html>

👇 下面是我的公众号,高质量的博文我会第一时间同步到公众号,给个关注吧!

评论列表

回复 Eddy 2016-06-14 14:06:47
哪里跨域了?