使用Ajax的post方式提交表单后,变成get方式

"本文探讨了如何在使用Ajax进行表单提交时,通过阻止`
`标签的默认提交行为,确保参数通过POST方式而不改变地址栏。关键在于设置`onsubmit="return false"`并结合Ajax实现数据传递。"
摘要由CSDN通过智能技术生成

 使用$ajax({type: "post" 或者 $.post()方式提交发现地址栏仍然发生改变,查看f12  发现还是使用的get方式提交的参数。

  常见的form表单提交方式,我的代码如下:

<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>test</title>
    <meta name="keywords" content="test">
    <meta name="description" content="test">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->
    <link th:href="@{/tools/css/bootstrap.min.css}" rel="stylesheet"/>

</head>
<body class="fixed-sidebar full-height-layout" style="overflow-y:hidden">

<div class="container-fluid bg_color">
        <div class="col-sm-6" id="left_from" style="overflow:scroll;padding-bottom: 20px;">
            <form class="form-horizontal m" id="form-convert-add" name="form-convert-add" >
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        <h3 class="panel-title">数据库配置</h3>
                    </div>
                    <div class="panel-body">

                        <div class="row">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">主机IP:</label>
                                    <div class="col-sm-8">
                                        <input id="hostName" name="hostName" class="form-control" type="text"
                                               placeholder="请输入主机IP"
                                               required/>
                                    </div>
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">端口:</label>
                                    <div class="col-sm-8">
                                        <input id="portNumber" name="portNumber" class="form-control" type="text"
                                               placeholder="请输入数据库端口" required/>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>

                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-primary" id="submitBt">提交</button>
                        <button id="stopConvert" class="btn btn-danger" type="button">重置</button>
                    </div>
                </div>
            </form>


        </div>

</div>
<!-- 全局js -->
<script type="text/javascript">

</script>

</body>
</html>
  <form class="form-horizontal m" id="form-convert-add" name="form-convert-add"  onsubmit="return false">
                <div class="panel panel-primary">
                    <div class="panel-heading">

关键点:要在Ajax提交方式中,把提交的按钮上设置   οnsubmit="return false"    阻止默认的提交。否则就会变成默认的提交方式。


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

angelasp

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值