第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用XMLHttpRequest發(fā)送POST數(shù)據(jù)

使用XMLHttpRequest發(fā)送POST數(shù)據(jù)

使用XMLHttpRequest發(fā)送POST數(shù)據(jù)我想在JavaScript中使用XMLHttpRequest發(fā)送一些數(shù)據(jù)。假設(shè)我在HTML中有以下表單:<form name="inputform" action="somewhere" method="post">     <input type="hidden" value="person" name="user">     <input type="hidden" value="password" name="pwd">     <input type="hidden" value="place" name="organization">     <input type="hidden" value="key" name="requiredkey"></form>如何在JavaScript中使用XMLHttpRequest編寫等效代碼?
查看完整描述

3 回答

?
慕田峪4524236

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個(gè)贊

下面的代碼演示了如何執(zhí)行此操作。


var http = new XMLHttpRequest();

var url = 'get_data.php';

var params = 'orem=ipsum&name=binny';

http.open('POST', url, true);


//Send the proper header information along with the request

http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');


http.onreadystatechange = function() {//Call a function when the state changes.

    if(http.readyState == 4 && http.status == 200) {

        alert(http.responseText);

    }

}

http.send(params);


查看完整回答
反對(duì) 回復(fù) 2019-05-29
?
三國(guó)紛爭(zhēng)

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超7個(gè)贊

var xhr = new XMLHttpRequest();

xhr.open('POST', 'somewhere', true);

xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

xhr.onload = function () {

    // do something to response

    console.log(this.responseText);

};

xhr.send('user=person&pwd=password&organization=place&requiredkey=key');

或者,如果您可以依賴瀏覽器支持,則可以使用FormData


var data = new FormData();

data.append('user', 'person');

data.append('pwd', 'password');

data.append('organization', 'place');

data.append('requiredkey', 'key');


var xhr = new XMLHttpRequest();

xhr.open('POST', 'somewhere', true);

xhr.onload = function () {

    // do something to response

    console.log(this.responseText);

};

xhr.send(data);


查看完整回答
反對(duì) 回復(fù) 2019-05-29
  • 3 回答
  • 0 關(guān)注
  • 9049 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)