var sUrl = "examtypeaction.phtm?action=setroletypes" + "&roleID="+ roleID +"&examTypeIDs=" + examTypeTree.getCheckedIDs();
var success = function(o) {
var s = o.responseText.toString();
var jsonObject = s.parseJSON(o.responseText);
var result = eval("jsonObject.result");
if (result.resultValue >0) {
alert("配置权限成功!");
}else{
alert('系统错误,请与系统管理员联系');
}
};
var callback = {
success : success
};
*** var req = $C.asyncRequest('POST', sUrl, callback);
由于examTypeIDs的长度会比较长,再加上url
的其它参数,整个url
提交时将近3400个字符串
这么长的字符串是不能直接提交的,超过了浏览器的限制(一说是最大长度是2048)
解决的办法是将url与参数分开,于是修改代码:
var sUrl = "examtypeaction.phtm?action=setroletypes" + "&roleID="+ roleID;
var xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttpReq.open("POST", sUrl, false);
*** xmlHttpReq.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded" );
*** xmlHttpReq.send("examTypeIDs=" + examTypeTree.getCheckedIDs());
var jsonObject = (xmlHttpReq.responseText.toString()).parseJSON(xmlHttpReq.responseText);
if(jsonObject) {
var result = eval("jsonObject.result");
if (result.resultValue >0) {
alert("配置权限成功!");
}else{
alert('系统错误,请与系统管理员联系');
}
}
修改之后问题成功解决,注意带****号行的区别
当我们将参数放在url中提交的时候,如果内容可能比较长的情况下
应当采用后面代码中的方法,避免出错
本文介绍了一种解决因URL参数过长导致的提交失败问题的方法。通过将长参数从URL中分离并使用POST请求发送,有效避免了浏览器对URL长度的限制。
759

被折叠的 条评论
为什么被折叠?



