jquery 1.7 无法将表单提交到特定 URL

jquery 1.7 cant submit the form to specific url

本文关键字:URL 表单提交 jquery      更新时间:2023-09-26

我想使用 $.post 将表单提交到特定 URL,我完全按照教程告诉我的去做。 这是我的代码

$(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 中有新的问号,我的意思是这个

提交前表单的网址

http://localhost:42344/WebForm1.aspx

提交后表单的网址

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

我做错了什么?

注意

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

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

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

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