jQuery page redirect after submit the form

后端 未结 5 1182
没有蜡笔的小新
没有蜡笔的小新 2021-01-13 22:36

I have a form like this

5条回答
  •  温柔的废话
    2021-01-13 22:41

    You can handle this in your action, you calling onSubmit() from server code redirect it to the page you want.

    Or you need to use ajax post() calls which give you onSuccess and onFailure events on call complete. Something like this:

    $('#add-to-cart').submit(function() {
        $.ajax({
            type: 'POST',
            url: $(this).attr('action'),
            dataType: 'json',
            success: function(json) {
               window.location.href = "http://www.page-2.com";
            }
        })
        return false;
    });
    

提交回复
热议问题