zoukankan      html  css  js  c++  java
  • ajax提交表单的几种形式

    https://blog.csdn.net/qq_17164811/article/details/78203766

    1.
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
        <script type="text/javascript">
            $(function(){

                $.ajax({
                    url:'xxxx',
                    type:'post',
                    dataType:'json',
                    data:{
                        'p1':$('#p1'),
                        'p2':$('#p2')
                    },
                    success:function(result){
                        //回调函数
                    }

                });


            });
        </script>
    </head>
    <body>
        <form id="myForm" action="">
            <input id="p1" name="p1" value="p1"/>
            <input id="p2" name="p2" value="p2"/>
            <input id="btn" type="button" value="提交"/>
        </form>
    </body>
    </html>

    2.$('#id').serialize( ); 这时表单的按钮的type不可以是submit,否则自提交数据,也就是自动刷新;改为button
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
        <script type="text/javascript">
            $(function(){

                $.ajax({
                    url:'xxxx',
                    type:'post',
                    dataType:'json',
                    data:$("#myForm").serialize(),
                    success:function(result){
                        //回调函数
                    }
                });


            });
        </script>
    </head>
    <body>
        <form id="myForm" action="">
            <input id="p1" name="p1" value="p1"/>
            <input id="p2" name="p2" value="p2"/>
            <input id="btn" type="button" value="提交"/>
        </form>
    </body>
    </html>

    3.使用jQuery Form插件提供的ajaxSubmit()函数
    $('#myform').ajaxSubmit({
    type: 'GET/POST',
    url: 'xx.php',
    dataType: 'json',
    success: fn,
    clearForm: true,
    resetForm: true
    }); 
  • 相关阅读:
    textarea 里设置 style="resize:none"
    linux 脚本
    RabbitMQ、Redis、ZeroMQ、ActiveMQ、Kafka/Jafka对比
    python安装过程
    linux下安装python3
    java实现定时任务 Schedule
    Spring 定时任务之 @Scheduled cron表达式
    docker部署
    设备连接服务器
    springboot实现fileUpLoad
  • 原文地址:https://www.cnblogs.com/lxh520/p/8760994.html
Copyright © 2011-2022 走看看