我已经查找并搜索过,但是找不到任何能真正解释如何通过XMLHttpRequest方法发送的内容。仅当单词本身带有大于或小于该符号的HTML时,即使我使用HTML特殊字符实体替换了大于或小于该符号的HTML,它也会引发403错误。显然,这是可能的,但是要做到这一点需要什么?
我正在尝试开发一个网站,在该网站上发布HTML和CSS PHP等,但是当我提交或保存它时,它会引发403(禁止)错误。这是我用来与服务器通信的ajax函数。
ajax : function(url,params, typ,callback) {
var xml;
if(window.XMLHttpRequest != 'undefined') {
xml = new window.XMLHttpRequest();
}
if(window.ActiveXObject) {
xml = new window.ActiveXObject('Microsoft.XMLHTTP');
}
xml.onreadystatechange = function() {
if(xml.readyState == 4 && xml.status == 200) {
xmlText = xml.responseText;
pXML = xml.responseXML;
if(callback != false) {
callback();
}
}
}
if(params == false && typ == 'GET') {
xml.open(typ,url,true);
xml.send(null);
}
if(params.length >= 1 && typ == 'POST') {
xml.open(typ,url,true);
xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
xml.send(params);
}
}
此代码在此处引发相同的403错误。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script type="text/javascript" src="/js/global.js"></script>
<script type="text/javascript">
function convert(str)
{
str = str.replace(/&/g, "&");
str = str.replace(/>/g, ">");
str = str.replace(/</g, "<");
str = str.replace(/"/g, """);
str = str.replace(/'/g, "'");
return str;
}
function goFind() {
console.log("Goes here");
var string = "<html>";
str = convert(string);
console.log(str);
var parms = 'txt='+encodeURIComponent(str);
lib.ajax('/txt.php',parms,'POST',function() {
console.log(xmlText);
});
}
window.onload = function() {
document.getElementsByClassName('fire')
[0].addEventListener("click",goFind);
}
</script>
<title>Document</title>
</head>
<body>
<span class="fire">some text down here</span>
</body>
</html>