3 回答
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形式傳過去。 |
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; } } |
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>
- 3 回答
- 0 關注
- 530 瀏覽
添加回答
舉報
