大家好,又见面了,我是你们的朋友全栈君。
根据约翰的回答,我将GET请求更改为POST请求。它可以工作,而无需更改服务器配置。所以我去寻找如何实现这一点。以下页面是有帮助的:
带有PHP的jQuery Ajax POST示例 (注意清理发布的数据注释)和
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:
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;
}
}
ajax POST Test
ajaxPOST.php:
lorem=_POST[‘lorem’];
print $lorem.’ ‘;
?>
我刚发送了12,000个字符,没有任何问题。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/138544.html原文链接:https://javaforall.cn