NutzCN Logo
问答 调用uploadifive后,form参数丢失
发布于 2453天前 作者 qq_ac45b36f 1964 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk
<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/platform/cms/banner" id="goBack" data-pjax><i class="ti-angle-left"></i>${msg['globals.button.back']}</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/cms/banner/addDo" method="post">
                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">名称</label>
                            <div class="col-sm-8">
                            <input type="text" id="name" class="form-control" name="name" data-parsley-required="true" placeholder="名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="type" class="col-sm-2 control-label">类型</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="type" id="type">
                                    <option value="0" selected>图片</option>
                                    <option value="1">视频</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="tag" class="col-sm-2 control-label">TAG</label>
                            <div class="col-sm-8">
                            <input type="text" id="tag" class="form-control" name="tag" data-parsley-required="true" placeholder="TAG">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="url" class="col-sm-2 control-label">资源路径</label>
                            <div class="col-sm-8">
                                 <div id="queue"></div>
                                 <div>
                                     <input id="file_upload" name="file_upload" type="file" multiple="false">
                                 </div>
                                 <div id="img" style="padding: 5px;">
                                 </div>
                                 <input type="hidden" id="url" name="url" value="" >
                             </div>
                        </div>
                        <div class="form-group">
                            <label for="location" class="col-sm-2 control-label">排序</label>
                            <div class="col-sm-8">
                            <input type="text" id="location" class="form-control" name="location" data-parsley-required="true" placeholder="排序字段">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="disabled" class="col-sm-2 control-label">是否禁用</label>
                            <div class="col-sm-8 switcha">
                                <div class="mr15">
                                    <input type="checkbox" id="disabled" name="disabled" class="js-switch-blue">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>
                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
                        </div>
                    </div>
                </div>
            </form>
        </section>
    </div>
</div>
<script language="JavaScript">
    $(document).ready(function () {
    		myForm.init();
    		function clearFile() {
            $("#img").html("");
            $("#queue").html("");
            $("#url").val("");
        }
    		
        $('#file_upload').uploadifive({
            'auto': true,
            'multi': false,
            'width': '100%',
            'height': '35',
            'buttonText': '请选择图片',
            'fileType': 'image/jpg,image/jpeg,image/png',
            'fileSizeLimit': 1024,
            'queueSizeLimit': 1,
            'formData': {},
            'queueID': 'queue',
            'uploadScript': '${base}/open/file/upload/image',
            'onUploadComplete': function (file, data) {
                data = JSON.parse(data);
                if (data.code == 0) {
                    Toast.success(data.msg);
                    $("#img").html("<img src='" + data.data + "' style='width:150px;height:95px;'>");
                    $("#url").val(data.data);
                } else {
                    clearFile();
                    Toast.error(data.msg);
                }
            },
            'onDrop': function (file, fileDropCount) {
                clearFile();
            },
            'onClearQueue': function (queue) {
                clearFile();
            },
            'onCancel': function () {
                clearFile();
            }
        });
        
        $('#addForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.code == 0) {
                    Toast.success(data.msg);
                    form.resetForm();
                    clearFile();
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });
    });
</script>
<%}%>

5 回复

你写的是:

'formData': {},

我的情况是:
A.如果不传图片,直接提交from是有数据传到后台的
B.如果上传了图片,返回url后,再提交from,from里就没有数据传到服务器上

我在另外的功能里,写法也是一样的,就没有出现以上情况,我找了很久找不到不同点,以下是我另外的功能代码

<%
layout("/layouts/platform.html"){
%>
<script src="${base!}/assets/plugins/ueditor/ueditor.config.js"></script>
<script src="${base!}/assets/plugins/ueditor/ueditor.all.min.js"></script>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/platform/call/activity" id="goBack" data-pjax><i class="ti-angle-left"></i>${msg['globals.button.back']}</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/call/activity/addDo" method="post">
                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label for="title" class="col-sm-2 control-label">标题</label>
                            <div class="col-sm-8">
                            <input type="text" id="title" class="form-control" name="title" data-parsley-required="true" placeholder="标题">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="info" class="col-sm-2 control-label">简介</label>
                            <div class="col-sm-8">
                                <textarea id="info" name="info" class="form-control" style="width:100%;height:80px;"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="place" class="col-sm-2 control-label">地点</label>
                            <div class="col-sm-8">
                            <input type="text" id="place" class="form-control" name="place" data-parsley-required="true" placeholder="地点">
                            </div>
                        </div>
                        <div class="form-group">
                             <label for="picUrl" class="col-sm-2 control-label">标题图</label>

                             <div class="col-sm-8">
                                 <div id="queue"></div>
                                 <div>
                                     <input id="file_upload" name="file_upload" type="file" multiple="false">
                                 </div>
                                 <div id="img" style="padding: 5px;">
                                 </div>
                                 <input type="hidden" id="picUrl" name="picUrl" value="" >
                             </div>
                         </div>
                         <div class="form-group">
                             <label for="content" class="col-sm-2 control-label">内容</label>

                             <div class="col-sm-8">
                                 <textarea id="content" name="content" style="width:100%;height:200px;"></textarea>
                             </div>
                         </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
                        </div>
                    </div>
                </div>
            </form>
        </section>
    </div>
</div>
<script language="JavaScript">
	function clearFile() {
	    $("#img").html("");
	    $("#queue").html("");
	    $("#picUrl").val("");
	    ue.setContent("");
	}
	var ue;
    $(document).ready(function () {
    	 	setTimeout(function () {
             ue = new baidu.editor.ui.Editor();
             ue.render('content');
         },500);
         $('#file_upload').uploadifive({
             'auto': true,
             'multi': false,
             'width': '100%',
             'height': '35',
             'buttonText': '请选择图片',
             'fileType': 'image/jpg,image/jpeg,image/png',
             'fileSizeLimit': 1024,
             'queueSizeLimit': 1,
             'formData': {},
             'queueID': 'queue',
             'uploadScript': '${base}/open/file/upload/image',
             'onUploadComplete': function (file, data) {
                 data = JSON.parse(data);
                 if (data.code == 0) {
                     Toast.success(data.msg);
                     $("#img").html("<img src='" + data.data + "' style='width:150px;height:95px;'>");
                     $("#picUrl").val(data.data);
                 } else {
                     clearFile();
                     Toast.error(data.msg);
                 }
             },
             'onDrop': function (file, fileDropCount) {
                 clearFile();
             },
             'onClearQueue': function (queue) {
                 clearFile();
             },
             'onCancel': function () {
                 clearFile();
             }
         });
        $('#addForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.code == 0) {
                    Toast.success(data.msg);
                    form.resetForm();
                    clearFile();
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });
    });
</script>
<%}%>


我参考的是:cms/article功能写的

你少了 @AdaptBy(type = WhaleAdaptor.class)

对比看看吧

谢谢,是我的错

添加回复
请先登陆
回到顶部