I'm currently creating a form to be submitted through javascript. Basically I started from the script posted in this answer, this is my version:
function open(method, url, data, target){
var form = document.createElement("form");
form.action = url;
form.method = method || "POST";
form.target = target || "_self";
if (data) {
for (var i = 0; i < data.length; i++) {
var input = document.createElement("textarea");
input.name = i.toString();
input.innerText = JSON.stringify(data[i]);
form.appendChild(input);
}
}
form.style.display = "none";
document.body.appendChild(form);
form.submit();
};
and I use it like this:
open("POST", "statistics.php", data, "newwin");
where data is an array of object like this:
var data = [{
"ticker": "SPM"
"date": "2013-01-03"
"time": "1000"
"kind": "S"
"price_in": "30.35"
"price:_out": "30.34"
"gain": "0.0100"
},
{
"ticker": "SPM"
"date": "2013-01-04"
"time": "1000"
"kind": "S"
"price_in": "30.22"
"price_out": "30.09"
"gain": "0.1300"
},
...];
My problem is that as soon as I try to retrieve this data from the statistics.php page with PHP I can't get any data.
if I try with var_dump($_POST);
and it gives me: array(0) { }
but if I check with Chrome devTools inside Network tab, all data are actually in the Header section.
What am I missing?