首页 > 代码库 > Ajax 图片上传

Ajax 图片上传

废话不说;直接上代码:

你懂得:

,导入js .

<script type="text/javascript"
    src=http://www.mamicode.com/"${pageContext.request.contextPath}/cmsui/javascript/jquery.js"></script>> 
<form id="imgfilesupload" action="file_imgFileUpload.action"
                    method="post" enctype="multipart/form-data" isclick="0">
                    <input type="file" name="file" dataType="Require" msg="请选择视频封面图片" />
                    <button id="imgsSubmit" type="button" class="button">上传</button>
                </form>
       $("#imgsSubmit").click(function() {
            imgsupload_video();
        });

        function imgsupload_video() {
            var tf = Validator.Validate($("#imgfilesupload")[0], 2);
            if (tf != true) {
                return;
            }
            
             $(this).attr("disabled","disabled");
            $("#imgfilesupload").ajaxSubmit({
                success : function(result) {
                    var num = result.replace(/<[^>]+>/g, "");
                    var msg = "成功!";
                    var isclick = "1";
                    if (num == "0") {
                        msg = "失败!";
                        isclick = "0";
                    } else if (num == "-1") {
                        msg = "图片格式不正确!";
                        isclick = "0";
                    }
                    top.Dialog.alerts("提示", msg, function() {
                        $("#imgurl").val(num);
                        $("#videoimg").attr("src",num);
                        $("#imgfilesupload").attr("isclick", isclick);
                    });
                }

            });
        }