0

I understand this mighty be a bit confusing, but:

I am using var finalData = String.fromCharCode(data1); to pack one char in one byte. It works exactly as it should.

The problem now is, I send the packed data using HTTP post. Javascript sends exactly 1 byte, and PHP receives 1 most of the time! This is not what I am trying to do. If I pack the number 10, according to the ascii table it's the new line character. When I send the packed character, while javascript sends one character, PHP receives more than one for some reason. Evyrthing works well if the number is 0 or 1 or 11.

How can I force javascript send my byte to PHP without messing up with it?

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();
}
Luka
  • 1,761
  • 2
  • 19
  • 30

0 Answers0