Created
July 2, 2017 09:45
-
-
Save yano3nora/15989f0a372f1b6095d7450d6081439c to your computer and use it in GitHub Desktop.
[js: createElement('form')] formエレメント仮想的に作ってPOSTする。 #js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// フォームタグを生成 | |
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