表单 - 数据提交

<script type="text/javascript">
    $(function () {
        $("#loginInputForm").form({
            url:"<%=homePage%>/t00_userController.json?login",
            success:function(data){
                data = eval("("+data+")");
                console.log(data.st);
                if ("-1" == data.st){
                    $.messager.alert(‘警告‘,"登陆失败");
                }else{
                    $.messager.alert(‘提示‘,"登陆成功");
                }
            }
        })
        $("#loginAndRegDialog").dialog({
            title: ‘登陆‘,
            width: 200,
            height: 200,
            closable: false,
            modal: true,
            buttons: [
                {
                    text: ‘登陆‘,
                    handler: function () {
                        console.log("登陆");
                        $("#loginInputForm").submit();
                    }
                }, {
                    text: "注册",
                    handler: function () {
                        console.log("注册");
                    }
                }

            ]
        })
    })

</script>

ajax提交表单数据

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%
    String homePage = request.getContextPath();
%>
<!DOCTYPE HTML>
<html>
<head>
    <title>首页</title>
    <meta charset="UTF-8"/>
    <link rel="stylesheet" type="text/css" href="<%=homePage%>/jslib/jquery-easyui-1.5/themes/default/easyui.css"
          charset="utf-8"/>
    <link rel="stylesheet" type="text/css" href="<%=homePage%>/jslib/jquery-easyui-1.5/themes/icon.css"
          charset="utf-8"/>
    <script type="text/javascript" src="<%=homePage%>/jslib/jquery-easyui-1.5/jquery.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=homePage%>/jslib/jquery-easyui-1.5/jquery.easyui.min.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="<%=homePage%>/jslib/jquery-easyui-1.5/locale/easyui-lang-zh_CN.js"
            charset="utf-8"></script>

</head>
<body class="easyui-layout">
<div data-options="region:‘west‘,title:‘左边栏‘,split:true" style="width:100px;"></div>
<div data-options="region:‘center‘,title:‘中心内容‘" style="padding:5px;background:#eee;"></div>

<div id="loginAndRegDialog">
    <form id="loginInputForm" method="post">
        <table align="center">
            <tr>
                <td align="right">用户名</td>
                <td>
                    <input type="text" name="username"/>
                </td>
            </tr>
            <tr>
                <td align="right">密码</td>
                <td>
                    <input type="password" name="password"/>
                </td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
    $(function () {
        $("#loginAndRegDialog").dialog({
            title: ‘登陆‘,
            width: 200,
            height: 200,
            closable: false,
            modal: true,
            buttons: [
                {
                    text: ‘登陆‘,
                    handler: function () {
                        console.log("登陆");
                        var dateJson = {
                            username: $("input[name=‘username‘]").val(),
                            password: $("input[name=‘password‘]").val()
                        };
                        console.log($("#loginInputForm").serialize());
                        console.log($("#loginInputForm").serializeArray());
                        console.log(JSON.stringify(dateJson));//可以
                        var data = {};
                        $("#loginInputForm").serializeArray().map(function(x){
                            if (data[x.name] !== undefined) {
                                if (!data[x.name].push) {
                                    data[x.name] = [data[x.name]];
                                }
                                data[x.name].push(x.value || ‘‘);
                            } else {
                                data[x.name] = x.value || ‘‘;
                            }
                        });
                        console.log(JSON.stringify(data));//可以
                        $.ajax({
                            type: "POST",
                            url: "<%=homePage%>/t00_userController.json?login",
                            data: JSON.stringify(data),
                            cache: false,
                            dataType: "json",
                            contentType: ‘application/json;charset=utf-8‘,
                            success: function (data) {
                                if ("-1" == data.st) {
                                    $.messager.alert(‘警告‘, "登陆失败");
                                } else {
                                    $.messager.show({
                                        title: ‘提示‘,
                                        msg: ‘登陆成功‘,
                                        timeout: 5000,
                                        showType: ‘slide‘
                                    });
                                    $("#loginAndRegDialog").dialog("close");
                                    <%--$("body").append("<a id=‘id1‘ href=‘<%=homePage%>/goPage.html?pagePath=work‘><span id=‘sp1‘></span></a>");--%>
//                                        $("#sp1").click();
                                }
                            }

                        })
                    }
                }, {
                    text: "注册",
                    handler: function () {
                        console.log("注册");
                    }
                }

            ]
        })
    })

</script>
</body>
</html>
时间: 2024-08-25 10:34:47

表单 - 数据提交的相关文章

使用jQuery实现跨域提交表单数据

我们在WEB开发中有时会遇到这种情况,比如要从A网站收集用户信息,提交给B网站处理,这个时候就会涉及到跨域提交数据的问题.本文将给您介绍如何使用jQuery来实现异步跨域提交表单数据. 在jQuery中,我们使用json数据类型,通过getJSON方法来实现从服务端获取或发送数据,而当要向不同远程服务器端提交或者获取数据时,要采用jsonp数据类型.使用这种类型的话,会创建一个查询字符串参数 callback=? ,这个参数会加在请求的URL后面.服务器端应当在JSON数据前加上回调函数名,以便

Struct2提交表单数据到Acion

Struct2提交表单数据到Action,Action取表单的数据,传递变量.对象 HTML.jsp <form action="reg.do" method="post"> <input> LoginAction get post 1.action里通过属性获取get.set方法获取. 2.模型驱动 3.model对象 action中要有和表单域对应的属性名,并且要有相应的符合javabean规范的set和get方法 http://blog

解决表单GET提交后台数据乱码问题

?在页面上提交数据到服务器有两种方式"GET"和"POST",当使用"GET"时,传输的数据是直接拼接在URL后面的.当数据中含有对HTML来说不安全的字符例如中文时,就会被编码,一般采用的是UTF-8编码.这时URL已经被转义成相对安全的字符串.此时再经过ios-8859-1的编码方式转换成二进制的形式跟随请求头一起发送到服务器端. ?到达服务器端时,服务器也对数据进行两次解码,服务器先把数据经过ios-8859-1解码,然后根据服务器默认的编

asp.net MVC中控制器获取表单form提交的数据之实体类数据

第一次写记录文章,难免有不足之处:欢迎指出. 1.新建一个mvc项目如: 2.新建一个Test.cs 注意get,set方法不能简写 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 using System; using System.Collections.Generic; using System.Linq; usi

easyui不提交window中的form表单数据

<form id="ff" method="post">, <div id="win" class="easyui-window" title="系统登录" style="width: 345px; height: 180px; padding: 10px" data-options="modal:true,collapsible:false,minimiza

7、struts2 案例( 模型驱动、 防止表单重复提交--拦截器 、数据回显 、值栈 、 OGNL表达式综合运用)

struts2 案例 技术点: 模型驱动 防止表单重复提交–拦截器 数据回显 值栈 OGNL表达式 通配符.路径匹配原则.常量 数据处理的集中方式 请求数据自动封装以及类型转换 1.导包 c3p0-0.9.1.2.jar commons-dbutils-1.6.jar commons-fileupload-1.2.2.jar commons-io-2.0.1.jar commons-lang3-3.1.jar freemarker-2.3.19.jar javassist-3.11.0.GA.j

jQuery通过AJAX快速提交表单数据

当表单数据项很多时,手动获取表单项的值将变得效率低下,结合jQuery提供的函数serialize(),我们可以实现快速获取数据并提交表单数据. 请看下面的表单: <form id="fm"> <table> <tr> <td>姓名</td> <td> <input type="text" name="name" /> </td> </tr>

通过js,修改所有form表单,提交JSON格式的数据

直接上代码 <script>$(function(){ //获取网页中所有的form表单 $("form").each(function(){ //注册表单的提交事件 $(this).submit(function(event) { //屏蔽表单的注册 event.preventDefault(); //获取url var url = $(this).attr("action"); request(url, 'POST', JSON.stringify(

Jquery serialize()提交多个表单数据

ajax提交多个表单数据: 先把不同的表单分别用serialize()函数,然后把序列化后的数据用+拼接提交给后台,具体例子如下 var data1 = $('#form1).serialize(); var data2 = $('#form2).serialize(); $.ajax({     url: url,     type: 'POST',     dataType: 'json',     data: data1+data2,    success: function (resul