Ajax呼叫不会转到控制器

时间:2019-05-09 08:37:49

标签: ajax spring-boot

这是寄存器的形式:

              <form name="signupForm" class="signupForm"
                         >
                        <div class="form-group">
                            <input type="text" class="form-control" name="mobilePhone"
                                   id="mobile-phone" placeholder="Mobil Tel">
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" name="name" id="name"
                                   placeholder="İsim">
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" name="lastName" id="last-name"
                                   placeholder="Soy İsim">
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" name="tckn" id="tckn"
                                   placeholder="TCKN">
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" name="email" id="e-mail"
                                   placeholder="E-posta">
                        </div>
                        <div class="form-group">
                            <div class="pwdMask">
                                <input type="password" class="form-control" name="password" id="password"
                                       placeholder="Şifre"> <span
                                    class="fa fa-eye-slash pwd-toggle"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <button id="registerBtn" class="btn btn-lg btn-primary btn-block" type="button">Kayıt
                                ol
                            </button>
                        </div>
                    </form>

对于按钮,我定义了以下行为:

  <script type="text/javascript">


    $('#registerBtn').click(
 function (event) {
            event.preventDefault();

            fireRegisterAccount();
 function fireRegisterAccount() {

                var mobilePhone = $('#mobile-phone').val();
                var name = $('#name').val();
                var lastName = $('#last-name').val();
                var tckn = $('#tckn').val();
                var email = $('#e-mail').val();
                var password = $('#password').val();

                var data = "mobilePhone=" + mobilePhone +
                    "&name=" + name
                    + "&lastName=" + lastName
                    + "&tckn=" + tckn
                    + "&email=" + email
                    + "&password=" + password;

                console.log("data paramters:"+data);


                $.ajax({
                    url: '/register',
                    data: data,
                    type: "POST",

                    success: function (response) {
                        debugger
                        console.log("response: " + response);
                    },
                    error: function () {
                        debugger
                        console.log("fail")
                    }
                });



            }

        });


</script>

但是它不会进入弹簧启动控制器。

相反,我看到它在浏览器的控制台中检索相同的页面:

response: <!DOCTYPE html> <html lang="tr"> <head>
    <!-- Basic Page Needs
      ================================================== -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatibl

出什么问题了?库?

js和html在同一个类中。

我在html正文中也有这个

<!-- initialize jQuery Library -->
<script src="landing/js/jquery-3.3.1.min.js"></script>
<!-- for Bootstrap js -->
<script src="landing/js/bootstrap.min.js"></script>
<!-- Custom js-->
<script src="landing/js/custom.js"></script>
<script src="landing/js/jquery.mask.min.js"></script>

当我单击时,我看不到任何错误。它会打个电话,但不会打给我的控制器。因为它不会调试。

它不是很多参数,因为我减少到一个,但仍然相同。

我也尝试过,但还是一样:

    var baseurl = $('body').data('baseurl');
$("#savecountry").click(function () {
    $.ajax({
        type: "POST",
        url: baseurl+'/Country/SaveCountry',

当我检查时,看到的是302状态代码:

http://localhost:8080/?mobilePhone=5427886263&name=fsa&lastName=qq&tckn=21321&email=5324367390&password=asfas

后端控制器:

@ResponseBody
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public ResultLang registerToSystem(
            @RequestParam("mobilePhone") String mobilePhone,
            @RequestParam("name") String name,
            @RequestParam("lastName") String lastName,
            @RequestParam("tckn") String tckn,
            @RequestParam("email") String email,
            @RequestParam("password") String password,
            HttpServletRequest request){
//code but does not come here
}

所有这些输入都在数据面板中:

 data-panel=".panel-signup"

从顶部调用:

<a class="lnk-toggler"
                                                  data-panel=".panel-signup" href="#">Kayıt ol!</a>

可能是原因吗?

它还调用 http://localhost:8080/login 当我查看浏览器的网络标签时。但是它不应该调用。无处可呼。

register的数据面板属于登录面板,但是我删除了action:login来查看。所以它不应该登录

0 个答案:

没有答案