Skip to content

Instantly share code, notes, and snippets.

@yano3nora
Created July 2, 2017 09:45
Show Gist options
  • Save yano3nora/15989f0a372f1b6095d7450d6081439c to your computer and use it in GitHub Desktop.
Save yano3nora/15989f0a372f1b6095d7450d6081439c to your computer and use it in GitHub Desktop.
[js: createElement('form')] formエレメント仮想的に作ってPOSTする。 #js
// フォームタグを生成
var form = document.createElement('form');
// フォームのmethodタイプ
form.method = 'POST';
// POST先
form.action = 'http://xxx.com/';
// POSTパラメーターようにinputタグを生成
var reqElm = document.createElement('input');
// nameとvalueにそれぞれPOSTしたいパラメーターを追加
reqElm.name = 'id';
reqElm.value = 1;
// フォームタグにinputタグを追加
form.appendChild(reqElm);
// bodyにフォームタグを追加
document.body.appendChild(form);
// 生成したフォームをSUBMIT
form.submit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment