我明白这有点令人困惑,但是:
我使用var finalData = String.fromCharCode(data1);
在一个字节中打包一个char。它完全按照预期工作。
现在的问题是,我使用HTTP post发送打包数据。 Javascript正好发送1个字节,PHP接收1 最多的时间!这不是我想要做的。如果我打包数字10
,根据ascii表,它是新行字符。当我发送打包字符时,当javascript发送一个字符时,PHP会因某种原因收到多个字符。如果数字为0或1或11,Evyrthing效果很好。
如何强制javascript将我的字节发送到PHP而不会搞砸它?
function post_to_url(path, data, method) {
method = method || "post"; // Set method to post by default if not specified.
// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", data);
form.appendChild(hiddenField);
document.body.appendChild(form);
form.submit();
}