Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

It is a modified version of Alfrekjv'sAlfrekjv's answer

It is a modified version of Alfrekjv's answer

It is a modified version of Alfrekjv's answer

added 16 characters in body
Source Link
rybo111
  • 12.5k
  • 4
  • 63
  • 72
<form action="/my/ajax/url">url" class="my-form">
...
</form>
<script>
    (function($){
        $("body").on("submit", ".my-form", function(e){
            e.preventDefault();
            var form = $(e.target);
            $.post( form.attr("action"), form.serialize(), function(res){
                console.log(res);
            });
        });
    )(jQuery);
</script>
<form action="/my/ajax/url">
...
</form>
<script>
    (function($){
        $("body").on("submit", ".my-form", function(e){
            e.preventDefault();
            var form = $(e.target);
            $.post( form.attr("action"), form.serialize(), function(res){
                console.log(res);
            });
        });
    )(jQuery);
</script>
<form action="/my/ajax/url" class="my-form">
...
</form>
<script>
    (function($){
        $("body").on("submit", ".my-form", function(e){
            e.preventDefault();
            var form = $(e.target);
            $.post( form.attr("action"), form.serialize(), function(res){
                console.log(res);
            });
        });
    )(jQuery);
</script>
added 594 characters in body
Source Link
Timo Huovinen
  • 55k
  • 33
  • 157
  • 148

Not tested with files

Does not send files, does not support buttons, for example clicking a button (including a submit button) sends its value as form data, but because this is an ajax request the button click will not be sent.

Not tested with files

Does not support buttons, for example clicking a button (including a submit button) sends its value as form data, but because this is an ajax request the button click will not be sent.

Does not send files, does not support buttons, for example clicking a button (including a submit button) sends its value as form data, but because this is an ajax request the button click will not be sent.

added 490 characters in body
Source Link
Timo Huovinen
  • 55k
  • 33
  • 157
  • 148
Loading
added 14 characters in body
Source Link
Timo Huovinen
  • 55k
  • 33
  • 157
  • 148
Loading
Source Link
Timo Huovinen
  • 55k
  • 33
  • 157
  • 148
Loading