ajax post参数提交过长,报400错误

利用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("失败");

            }
           
        }
       
    }

 

posted @ 2017-06-13 17:15  张追逐  阅读(4655)  评论(0编辑  收藏  举报