There is no way to provide pure binary data in the POST, however with the combination of JSON and a server side script able to parse JSON into a hash array, you can fake it using a hidden form field.
First, go to http://www.json.org/ and download json2.js, this provides the ability for JavaScript to safely encode and decode a JSON string and guards against cross site scripting attacks. Now you can pass arbitrarily deep data structures to the backend:
JavaScript/HTML
Code:
<script>
var data = {
title: "Jobs",
names: ["John", "Bill", "Stacey"],
positions: [
{title: "Engineer", id: 1},
{title: "Manager", id: 2}
]
};
document.getElementById("my_form").onclick = function() {
this.elements.json.value = JSON.stringify(data);
};
</script>
<form id="my_form">
... visible form fields
<input type="hidden" name="json">
</form>
And on the server side:
PHP
Code:
$data = json_decode($_POST['json']);
echo $data['title'];
echo $data['names'][1];
echo $data['positions'][0]['title'];
Bookmarks