通过jQuery AJAX提交HTML表单()和序列化() [英] submitting html form via jquery ajax() and serialize()

查看:137
本文介绍了通过jQuery AJAX提交HTML表单()和序列化()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要提交通过jQuery AJAX这种形式,这就是我已经和它不工作。即表格的提交与刷新页面,我没有看到,即在同一页上打印阵列的响应。

HTML

 <链接相对=样式类型=文本/ CSSHREF =CSS /胡椒研磨机/ jQuery的-UI-1.10.4.custom.css/&GT ;
    <脚本类型=文/ JavaScript的SRC =JS / jQuery的-1.10.2.js'>< / SCRIPT>
    <脚本类型=文/ JavaScript的SRC =JS / jQuery的-UI-1.10.4.custom.min.js'>< / SCRIPT>
        <表格ID =Form1上的方法=获得行动=submit.php>
            <标签>机构名称和LT的; /标签>
            <输入类型=文本名称=ORGNAMEID =ORGNAME级=文本框>
            <标签>组织与其中的地址; /标签>
            <输入类型=文本名称=OrgAddressID =OrgAddress级=文本框>
            <输入类型=提交值=注册机构>
        < /形式GT;
        < D​​IV ID =响应>广告< / DIV>

    <脚本>
    $的document.ready(功能(){
        $(#窗口1)。单击((函数(事件){
            。事件preventDefault();

            $阿贾克斯({
                    网址:submit.php,
                    键入:GET,
                    数据:$(本).serialize()
                    成功:函数(结果){
                        $(#响应)文本(结果)。

                    }

            });
        });
    });
    < / SCRIPT>
 

PHP(submit.php)

 < PHP
的print_r($ _ GET);
?>
 

解决方案

使用此,他们很少语法错误

  $(函数(){
        $(#窗口1)。点击(函数(事件){
            。事件preventDefault();

            $阿贾克斯({
                    网址:submit.php,
                    键入:GET,
                    数据:$(本).serialize()
                    成功:函数(结果){
                        $(#响应)文本(结果)。

                    }

            });
        });
    });
 

I want to submit this form via jquery ajax, this is what I have made and it is not working. i.e. Form is submitting with page refresh and I am not seeing the response i.e. printing array on the same page.

HTML

  <link rel='stylesheet' type='text/css' href='css/pepper-grinder/jquery-ui-1.10.4.custom.css' />
    <script  type='text/javascript' src='js/jquery-1.10.2.js' ></script>
    <script  type='text/javascript' src='js/jquery-ui-1.10.4.custom.min.js' ></script>
        <form  id="form1" method="get" action="submit.php   ">
            <label>Name of Organization</label>
            <input type="text" name="OrgName" id="OrgName" class="textfield">
            <label>Address of Organization</label>
            <input type="text" name="OrgAddress" id="OrgAddress" class="textfield">
            <input type="submit" value="Register Organization">
        </form>
        <div id="response">ads</div>

    <script>
    $document.ready(function(){
        $("#form1").click((function(event){
            event.preventDefault();

            $.ajax({
                    url:'submit.php',
                    type:'GET',
                    data:$(this).serialize(),
                    success:function(result){
                        $("#response").text(result);

                    }

            });
        });
    });
    </script>

PHP (submit.php)

<?php
print_r($_GET);
?>

解决方案

Use this , their were few syntax errors

 $(function(){
        $("#form1").click(function(event){
            event.preventDefault();

            $.ajax({
                    url:'submit.php',
                    type:'GET',
                    data:$(this).serialize(),
                    success:function(result){
                        $("#response").text(result);

                    }

            });
        });
    });

这篇关于通过jQuery AJAX提交HTML表单()和序列化()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆