+ -
当前位置:首页 → 问答吧 → 求助!!!Form表单提交的问题

求助!!!Form表单提交的问题

时间:2009-07-30

来源:互联网

大家好,请教一个问题:

现在我是通过jquery ui dialog实现了这样一个表单,如下:
<div id="dialog" title="添加新文件">
    <p id="validateTips">所有项必填</p>

    <form id="uploadForm" method="post" multipart/form-data" autocomplete="off">
        <fieldset>
            <label for="questions" >名称:</label>
            <input type="text" name="myname" id="myname" class="text ui-widget-content ui-corner-all" autocomplete="off"/>

            <label for="test_content" >描述:</label>
            <input type="text" name="descript" id="descript" class="text ui-widget-content ui-corner-all" />

            <label for="result" >文件:</label>
            <input type="file" name="uploadfile" id="uploadfile"/>
            <img id="loading" src="/../images/loading.gif" style="display:none;">
            
            <label for="star">难度级别:</label>
            <input class="star" type="radio" value="1" name="filelevel" style="display: none;"/>
            <input class="star" type="radio" value="2" name="filelevel" style="display: none;"/>
            <input class="star" type="radio" value="3" name="filelevel" style="display: none;" checked="checked"/>
            <input class="star" type="radio" value="4" name="filelevel" style="display: none;"/>
            <input class="star" type="radio" value="5" name="filelevel" style="display: none;"/>
        </fieldset>
    </form>
</div>

<button id="create-user" class="ui-button ui-state-default ui-corner-all">添加新内容</button>

下面的这部分代码是针对这个dialog的一些操作的:
jQuery( function($) {
    $("#dialog").dialog( {
        bgiframe : true,
        autoOpen : false,
        height : 500,
        width : 600,
        modal : true,
        buttons : {
            '提交' : function() {
                $.ajax({
                    type: "POST",
                    url: "/file/index/add",
                    dataType: "json",
                    success:function(){
                        alert("添加成功!");
                    },
                    error:function(){
                        alert("添加失败!");
                    }
                });
            },
            '重置' : function() {
                $("#uploadForm").each( function() {
                    this.reset();
                });
            },
            '关闭' : function() {
                $(this).dialog('close');
            }
        }
    });
    
    $('#create-user').click( function() {
        $('#dialog').dialog('open');
        $("#uploadForm").each( function() {
            this.reset();
        });
    });
}
请大家看一下“提交”这部分,现在的问题是,我要实现文件的上传和一些其他文本内容表单的处理,但是在.ajax提交数据的时候,我是提交到后台的PHP来处理的,现在却无法得到这些表单的值,请问这个如何处理呢?

因为我没有直接写表单的<input type="submit">所以在这不知该如何获取这些表单的值了?

请各位指教,谢谢

作者: jquerypp   发布时间: 2009-07-30

$.ajax({
                    type: "POST",
                    url: "/file/index/add",
                    dataType: "json",
                    success:function(){
                        alert("添加成功!");
                    },
                    error:function(){
                        alert("添加失败!");
                    }
                });
看一下这里,这里data部分没有数据,理论上ajax提交的时候应该这样:
$.ajax({
                    type: "POST",
                    url: "/file/index/add",
                    dataType: "json",
                    data:"xxx"
                    success:function(){
                        alert("添加成功!");
                    },
                    error:function(){
                        alert("添加失败!");
                    }
                });
这时,后台可以通过post取得参数值
不过你这里还有文件上传,用ajax不太方便

作者: uord   发布时间: 2009-08-02

相关阅读 更多