【问题标题】:jquery 1.7 cant submit the form to specific urljquery 1.7 无法将表单提交到特定的 url
【发布时间】:2013-10-24 12:05:47
【问题描述】:

我想使用$.post 将我的表单提交到特定的网址,我完全按照教程告诉我的内容进行操作。这是我的代码

$(document).ready(function () {
    $("#fLogin").on('submit', function (e) {
        var errorCount = 0;
        $('span.errorMessage').text('');
        $('input [type=text]').each(function () {
            var $this = $(this);
            if ($this.val() === '') {
                var error = 'Please fill ' + $this.prev('label').text(); // take the input field from label
                $this.next('span').text(error);
                errorCount = errorCount + 1;
            }
        });
        var select = $('#sUserType').filter(function () {
            if (this.selectedIndex == 0)
                errorCount = errorCount +1;
            return this.selectedIndex == 0;
        }).next('span').text('Please select user type');
        if (errorCount == 0) {
            var mobileNumber = $("#iMobileNumber").val();
            var password = $("#iPassword").val();
            $.post("MY URL");
            //$.ajax("ajax/test.html", function (data) {
              //  alert("d");
            //});
        }
        else
            e.preventDefault();
    });
});

但是当我按下提交按钮时,我只是在 url 中有一个新的问号,我的意思是这个

提交前表单的url

http://localhost:42344/WebForm1.aspx

提交后表单的url

http://localhost:42344/WebForm1.aspx?

请问我做错了什么?

注意

我可以更改密码和手机号码的值

【问题讨论】:

    标签: javascript jquery jquery-1.7


    【解决方案1】:

    您正在使用没有回调的 $.post 那么您希望看到什么? Post 将在后台运行,因为它是一个异步 HTTP (Ajax) 请求。也许您正在寻找:

    $('form').attr('action', "/yoururl").submit();
    

    http://api.jquery.com/submit/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-25
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多