码迷,mamicode.com
首页 > 其他好文 > 详细

easyui+ajaxfileupload,无刷新文件上传

时间:2014-05-09 12:31:49      阅读:467      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   tar   

头文件引用

bubuko.com,布布扣
<link href="easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
<link href="easyui/themes/icon.css" rel="stylesheet" type="text/css" />
<script src="easyui/jquery.min.js" type="text/javascript"></script>
<script src="easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="js/ajaxfileupload.js" type="text/javascript"></script>
bubuko.com,布布扣

js代码,这里把返回值修改成上传到服务器的文件名称,然后赋值给一个隐藏input,提交表单时以便入库

bubuko.com,布布扣
//文件上传
function ajaxFileUpload(){
    $("#loading")
    .ajaxStart(function(){
        $(this).show();
    })
    .ajaxComplete(function(){
        $(this).hide();
    });

    $.ajaxFileUpload
    (
        {
            url:‘upload.php‘,
            secureuri:false,
            fileElementId:‘fileToUpload‘,
            dataType: ‘json‘,
            data:{name:‘logan‘, id:‘id‘},
            success: function (data, status)
            {
                if(typeof(data.error) != ‘undefined‘)
                {
                    if(data.error != ‘‘)
                    {
                        alert(data.error);
                    }else{    
                        alert("上传成功")
                        $("#imgURL").attr("value",data.msg);
                        //alert(data.msg);
                        //$("#img").attr("src","upload/"+data.msg);
                        
                    }
                }
            },
            error: function (data, status, e)
            {
                alert(e);
            }
        }
    )

    return false;

}
bubuko.com,布布扣

表单上传部分

bubuko.com,布布扣
<input id="fileToUpload" type="file" size="45" name="fileToUpload" class="input"><button class="button" id="buttonUpload" onclick="return ajaxFileUpload();">上传</button>
                   <input name="imgURL" id="imgURL" class="easyui-validatebox" type="hidden">
bubuko.com,布布扣

 

easyui+ajaxfileupload,无刷新文件上传,布布扣,bubuko.com

easyui+ajaxfileupload,无刷新文件上传

标签:style   blog   class   code   java   tar   

原文地址:http://www.cnblogs.com/hzg4027/p/3708770.html

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