ajax中,發送請求的類型

來源:互聯網
上載者:User

標籤:緩衝   ati   分享   添加   xmlhttp   輸入   encode   cat   字元   

1.post請求

  在一下情況,使用post:

    無法使用快取檔案(補救伺服器上的檔案或資料庫);

    向伺服器發送大量資料(POST 沒有資料量限制);

    發送包含未知字元的使用者輸入時,POST 比 GET 更穩定也更可;

  eg:

  
xmlhttp.open("POST","demo_post.asp",true);xmlhttp.send();
post簡單例子

  如果需要像 HTML 表單那樣 POST 資料,請使用 setRequestHeader() 來添加 HTTP 頭。然後在 send() 方法中規定您希望發送的資料:

  
1 xmlhttp.open("POST","ajax_test.asp",true);2 xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");3 xmlhttp.send("fname=Bill&lname=Gates");
添加HTTP頭

  //setRequestHeader(header,value):

  //header: 規定頭的名稱;value: 規定頭的值;

2.get請求

  與 POST 相比,GET 更簡單也更快,並且在大部分情況下都能用。  注意:為了避免得到的是緩衝的結果,我們需要向URL添加一個唯一的ID,例如:

  
1 xmlhttp.open("GET","demo_get.asp?t=" + Math.random(),true);2 xmlhttp.send();
添加id

 

ajax中,發送請求的類型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.