我已经开发了一个PHP web应用程序。我给用户一个选择,以更新多个问题在一次去。在这样做的过程中,有时用户会遇到这个错误。有没有办法在apache中增加URL的长度?
发布于 2014-04-30 11:30:10
根据John的回答,我将GET请求更改为POST请求。它可以工作,而无需更改服务器配置。所以我开始研究如何实现这一点。以下几页很有帮助:
jQuery Ajax POST example with PHP (注意sanitize posted data注释)和
http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
基本上,不同之处在于GET请求将url和参数放在一个字符串中,然后发送null:
http.open("GET", url+"?"+params, true);
http.send(null);而POST请求在单独的命令中发送url和参数:
http.open("POST", url, true);
http.send(params);下面是一个有效的示例:
ajaxPOST.html:
<html>
<head>
<script type="text/javascript">
function ajaxPOSTTest() {
try {
// Opera 8.0+, Firefox, Safari
ajaxPOSTTestRequest = new XMLHttpRequest();
} catch (e) {
// Internet Explorer Browsers
try {
ajaxPOSTTestRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajaxPOSTTestRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
ajaxPOSTTestRequest.onreadystatechange = ajaxCalled_POSTTest;
var url = "ajaxPOST.php";
var params = "lorem=ipsum&name=binny";
ajaxPOSTTestRequest.open("POST", url, true);
ajaxPOSTTestRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxPOSTTestRequest.send(params);
}
//Create a function that will receive data sent from the server
function ajaxCalled_POSTTest() {
if (ajaxPOSTTestRequest.readyState == 4) {
document.getElementById("output").innerHTML = ajaxPOSTTestRequest.responseText;
}
}
</script>
</head>
<body>
<button onclick="ajaxPOSTTest()">ajax POST Test</button>
<div id="output"></div>
</body>
</html>ajaxPOST.php:
<?php
$lorem=$_POST['lorem'];
print $lorem.'<br>';
?>我刚刚发送了超过12,000个字符,没有任何问题。
https://stackoverflow.com/questions/2891574
复制相似问题