利用ajax的post方法調用web api接口,出現了以下錯誤
以下為代碼截圖:
很顯然,傳遞的參數過多導致的。
接下來,要怎么解決呢?
原來,post方式是由無限制的,而url是有限制的,那么就將url與傳遞的參數分開。
使用原生態的aiax的post
//創建請求 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.open("POST", "/DLWeb/api/WbsNode/EditPMLog?", false); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");//指定header xmlhttp.send(par); //響應請求 xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {//成功 if (xmlhttp.responseText == "true") { alert("成功"); } else {//失敗 alert("失敗"); } } }