开发者社区> 问答> 正文

jquery.form.js 二次提交出错

我是菜鸟,现在做一个表单的提交图片,用的jquery.form.js这个框架,第一次提交是正常的,但是第二次提交就会出错误,请大神指点下,这个是我的代码。
这是JS代码

 function formReady() {
    var options = {
            url:"user!upLoadFile.action",
            type:'post',
            dataType:'json',
            resetForm: true,
            clearForm: true,
            async :true, // 异步
            success: function(data){
                if(data.result == "noFile"){
                    alert("没有上传文件");
                    return;
                }else if(data.result == "error"){
                    alert("文件上传错误");
                    return;
                }else if(data.result == "norecord"){
                    alert("没有可添加记录的病历");
                    return;
                }
                var recordAdd = $("#recordAdd");
                var html = "";
                var recordAddText = recordAdd[0].innerHTML;
                var m_pic = $("#m-pic"); 
                if(m_pic[0] == null || m_pic[0] == ""){
                    html += '<div id="m-pic" class="m-at">';
                    html += '<div id="u-pic" class="u-cnt">附件管理      /  已添加<span id="pic-math">0</span>个附件</div>';
                    html += '<div class="u-line"></div>';
                    html += '<div class="u-pic">';
                    html += '<div id="pic-cnt" class="z-ctn" style="height:100%;width: 100rem">';
                    html += '</div>';
                    html += '</div>';
                    recordAdd.html(recordAddText+html);

                    html = "";
                }
                var z_pic = $("#pic-cnt");
                var path = data.path;
                var z_pic_text = z_pic[0].innerHTML;
                if(path != null){
                    html += '<div class="pic" id="'+ path.id +'">';
                    html += '<img alt="" src="'+ path.path.substring(path.path.indexOf("upload")) +'" onclick="toPicture('+ path.id +');"/>';
                    html += '<a href="javaScript:void(0)" onclick="deletePicture(this);">删除</a>';
                    html += '</div>';
                    z_pic.html(z_pic_text+html);

                    $("#pic-math").val($(".pic>img").length);

                    html = "";
                }

                var pic = $(".pic");
                var wid1 = pic.length;
                z_pic.offsetWidth;
                z_pic.css("width","calc("+ wid1 +" * 10rem + 1rem)");
            }
    };

    $("#form").ajaxSubmit(function(){
        $("#form").ajaxForm(options);
    });
    //$("#form").ajaxForm(options);

}

function addRecodeClick(){
    $("#file").click();
}

function fileChange(){
    if(this.value == ""){
        return;
    }else{
        $("#submit").click();
    }
}
这是html
 <form id="form" action="" onsubmit="formReady();" enctype="multipart/form-data" method="post">
                            <input id="recordId" type="hidden" name="recordId"/>
                            <a href="javaScript:void" onclick="addRecodeClick()">添加附件</a>
                            <input id="file" name="file" type="file" style="display: none" onchange="fileChange();" accept=".jpg,.png,.gif,.jpeg"/><br/>
                            <input id="submit" type="submit" value="upload" style="display: none"/>
                        </form>

展开
收起
小旋风柴进 2016-03-20 09:19:05 2792 0
1 条回答
写回答
取消 提交回答
  • $("#form").ajaxSubmit(function(){
    $("#form").ajaxForm(options);
    });

    $("#form").ajaxForm(options);,ajaxForm的使用方法,

    2019-07-17 19:08:35
    赞同 展开评论 打赏
问答地址:
相关产品:
问答排行榜
最热
最新

相关电子书

更多
23-Vue.js在前端...1506518547.pdf 立即下载
Javascript中的函数 立即下载
JavaScript函数 立即下载