petko_stankoski
petko_stankoski

Reputation: 10713

Ajax after form submit doesn't work

I have this:

$('#my_form').submit(function () {
        setTimeout(function () {
            console.log('1');
            $.ajax({
                type: "GET",
                url: "/CorrectUrl/CorrectUrl",
                data: {},
                success: function (data) {
                    console.log('2');
                },
                error: function (a, b, c) {
                    console.log(a);
                }
            });
        }, 100);
    });

And the url for the form is called and executed. The form returns value. But CorrectUrl isn't getting called. Why?

Upvotes: 0

Views: 157

Answers (1)

John Conde
John Conde

Reputation: 219824

You need to stop the default action from occuring with preventDefault()

$('#my_form').submit(function (e) {
    e.preventDefault();

Upvotes: 7

Related Questions