简体   繁体   中英

jquery 1.7 cant submit the form to specific url

i want to submit my form to a specific url using $.post , i followed exactly what the tutorial told me. this is my code

$(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();
    });
});

but when i press the submit button, i just have new question mark in the url, i mean this

the url of the form before submit

http://localhost:42344/WebForm1.aspx

the url of the form after submit

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

what am i doing wrong pelase?

note

i can alter the value of password and mobilenumber

You are using $.post with no callbacks so what do you expect to see? Post will run in the background because it's an asynchronous HTTP (Ajax) request. Perhaps you are looking for:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM