1

を使用してフォームを特定の URL に送信したいのですが$.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?

私は何を間違っていますか?

ノート

パスワードと携帯電話番号の値を変更できます

4

1 に答える 1

3

コールバックなしで $.post を使用している場合、何が表示されると思いますか? Post は非同期の HTTP (Ajax) リクエストであるため、バックグラウンドで実行されます。おそらくあなたは探している:

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

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

于 2013-10-24T12:16:43.940 に答える