亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問jquery發送ajax請求,參數怎么放到http請求的body里面?

請問jquery發送ajax請求,參數怎么放到http請求的body里面?

滄海一幻覺 2019-07-09 05:04:14
請問jquery發送ajax請求,參數怎么放到http請求的body里面?
查看完整描述

3 回答

?
qq_花開花謝_0

TA貢獻1835條經驗 獲得超7個贊


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

$.ajax({  

    url:"xxxxxx",

    type:"post",  

    dataType:"json",  

    data:"hello world",  

    headers: {'Content-Type': 'application/json'},  

    success: function (ret) {    

        if (ret.status == 1) {      

            window.location.reload();    

        } else {      

            alert(ret.message);    

        }  

    }

})    

使用post請求,這里的data里的參數就是在body形式傳過去。




查看完整回答
反對 回復 2019-07-10
?
有只小跳蛙

TA貢獻1824條經驗 獲得超8個贊

1

2

3

4

5

6

7

8

public boolean isAjaxRequest(HttpServletRequest request){  

    String header = request.getHeader("X-Requested-With");

    if ("XMLHttpRequest".equals(header)) {

        return true;

    } else {

        return false;

    }

}



查看完整回答
反對 回復 2019-07-10
?
心有法竹

TA貢獻1866條經驗 獲得超5個贊


普通情況下沒法判斷不過如果使用jquery做ajax 會自動在請求的header里面加上一個 x-request-with 可以通過這個判斷。望采納! <html><!DOCTYPE html> <html> <head> <script> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","/try/ajax/demo_get.php",true); xmlhttp.send(); } </script> </head> <body> <h2>AJAX</h2> <button type="button" onclick="loadXMLDoc()">Request data</button> <div id="myDiv"></div> </body> </html>



查看完整回答
反對 回復 2019-07-10
  • 3 回答
  • 0 關注
  • 530 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號