1 <SCRIPT> 2 window.addEventListener( '負荷'、関数(EV){ 3。 VARの BTN =のdocument.getElementById( '送信' ); 4 btn.addEventListener( 'クリック'、関数(EV1){ 5。 6。 // 1。ユーザによるコンテンツの入力を取得 7。 VARアカウント=のdocument.getElementById( 'アカウント' ).Valueのを、 8 VAR PWD =のdocument.getElementById( 'PWD' ).Valueのを; 9 10 // 2.ネットワーク要求オブジェクトを作成する 。11 のvar XHR = 新しい新しいのXMLHttpRequest(); 12は、 xhr.open( 'ポスト'、 'のhttp:// localhostを:3000 / API / 5'、真の); 13 // 设置请求头 14 xhr.setRequestHeader( 'コンテンツタイプ'、 'アプリケーション/ x-www-form-urlencodedで' )。 15 16 xhr.send( '名前=のZS&年齢= 19' ); 17 xhr.addEventListener( 'readystatechange'、関数(EV2){ 18 であれば(xhr.readyState === 4 ){ 19 であれば(xhr.status === 200 ){ 20 にconsole.log(xhr.responseText); 21 } 他に{ 22 console.log( 'リクエストが失敗した!' ); 23がある } 24 } 25 }); 26れる }); 27 }); 28 </ SCRIPT>