我的 javascript 发布请求有问题。
我有以下代码用于发送帖子请求
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
//stuff
}
};
xhttp.open("POST", "/deleteUser", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("username=" + username);
在我的 Node.js Express 应用程序中,我像这样收到它
var username = req.body.username;
现在这可以完美地处理普通字符(数字和字母)。但是当我尝试时
>df)(*&&^%$
作为用户名,它被 chop 为
>df)(*
我怀疑这是因为&。
我的问题:如何防止它被切断。
提前致谢!
最佳答案
您需要使用 xhttp.send("username="+encodeURIComponent(username)); 将
username
参数转换为 URI 安全字符串;
关于javascript - 发布请求被切断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42951151/