変数 = new FormData();
《FormData》.append( 名前 , 値 );
new FormData(document.querySelector("#form1"));――こんな具合ですね。注意したいのは、フォーム内に用意する入力関係のタグは、必ずname属性を指定しておく、ということです。忘れるとうまく値が取り出せません。
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
<!DOCTYPE html> <html lang="ja"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>タイトル</title> <style> h1 { font-size: 18pt; background: #AAAAEE; padding: 5px;} </style> <script type="text/javascript"> function doAction(e){ var formData = new FormData(); formData.append('id', 123); formData.append('name', "tuyano"); formData.append('password', "hoge"); var xhr = new XMLHttpRequest(); xhr.open('POST', '/helo.php', true); xhr.responseType = 'text'; xhr.onload = function(e) { if (this.status == 200) { document.querySelector("#msg").innerHTML = this.response; } }; xhr.send(formData); } </script> </head> <body> <header> <h1>XHR2 Sample</h1> </header> <article> <p id="msg"></p> <button onclick="doAction();">Click</button> </article> </body> </html>
<< 前へ | 次へ >> |