白嫩娇妻被交换经过_被弄出白浆喷水了视频_亚洲依依成人_小蝌蚪视频污下载

當(dāng)前位置: 首頁(yè) / 技術(shù)干貨 / 正文
ajax 常見(jiàn)請(qǐng)求方式有哪些?

2023-03-22

   xhr  ○

ajax 常見(jiàn)請(qǐng)求方式有哪些

  ajax 常見(jiàn)請(qǐng)求方式有哪些

  ● GET

  ○表示向服務(wù)器獲取資源

  ●POST

  ○表示向服務(wù)器提交信息,通常用于產(chǎn)生新的數(shù)據(jù),比如注冊(cè)

  ●PUT

  ○表示希望修改服務(wù)器的數(shù)據(jù), 通常用于修改某數(shù)據(jù)

  ●DELETE

  ○表示希望刪除服務(wù)器的數(shù)據(jù)

  ●OPTIONS

  ○發(fā)生在跨域的預(yù)檢請(qǐng)求中,表示客戶端向服務(wù)器申請(qǐng)跨域提交

  ajax 中 get 和 post 請(qǐng)求攜帶參數(shù)的方式

  ●GET: 直接拼接在請(qǐng)求路徑后, 以 ? 間隔, 使用 key=value 的形式書(shū)寫(xiě), 當(dāng)有多個(gè)參數(shù)的時(shí)候用 & 連接

  const xhr = new XMLHttpRequest()

  xhr.open('GET', 'http://localhost:8888/test/third?name=QF666&age=18')

  xhr.send()

  xhr.onload = function () {

  let res = JSON.parse(xhr.responseText)

  console.log(res)

  }

  ●POST

  ○在請(qǐng)求體內(nèi)攜帶參數(shù)(其實(shí)就是 send 小括號(hào)內(nèi)部)

  ○并且需要設(shè)置請(qǐng)求頭內(nèi)部的 content-type

  ■如果參數(shù)為 查詢字符串, 需要添加:

  ●'xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded')'

  ■如果參數(shù)為 JSON 字符串, 需要添加:

  ●'xhr.setRequestHeader('content-type', 'application/json')'

  const xhr = new XMLHttpRequest()

  xhr.open('POST', 'http://localhost:8888/test/fourth')

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

  xhr.send('name=QF666&age=18')

  xhr.onload = function () {

  let res = JSON.parse(xhr.responseText)

  console.log(res)

  }

好程序員公眾號(hào)

  • · 剖析行業(yè)發(fā)展趨勢(shì)
  • · 匯聚企業(yè)項(xiàng)目源碼

好程序員開(kāi)班動(dòng)態(tài)

More+
IT培訓(xùn)IT培訓(xùn)
在線咨詢
IT培訓(xùn)IT培訓(xùn)
試聽(tīng)
IT培訓(xùn)IT培訓(xùn)
入學(xué)教程
IT培訓(xùn)IT培訓(xùn)
立即報(bào)名
IT培訓(xùn)

Copyright 2011-2023 北京千鋒互聯(lián)科技有限公司 .All Right 京ICP備12003911號(hào)-5 京公網(wǎng)安備 11010802035720號(hào)