LoginSignup
5
9

More than 5 years have passed since last update.

jQuery で form を動的に追加して POST する(target 付き)

Posted at

jQuery で form を動的に追加して POST するサンプルです。

$(/*document).ready(*/function () {
    $('.some_buttons_class').click(function () {
        var $fm = $('<form />', {
            method: 'post',
            action: 'action_receiver.php',
            target: '_blank',
        });
        $fm.append($('<input />', {
            type: 'hidden',
            name: 'data_id',
            value: $(this).data('id'),
        }));
        $fm.appendTo(document.body);
        $fm.submit();
        $fm.remove();
    });
});

ググって最初に出てくるサンプルが最後の .remove() をしておらず気持ち悪かったので投稿しました。

5
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
9