0

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Plastic
  • 9,874
  • 6
  • 32
  • 53
  • 1
    Add `data` too in the question.. – Rayon Feb 19 '16 at 16:54
  • 'data' added to the question – Plastic Feb 19 '16 at 17:00
  • Can't understand why people downvotes, is it an outrageous question? :o – Plastic Feb 19 '16 at 17:06
  • Tested the same and it is working..`$_POST` => `array (size=2) 0 => string '{"ticker":"SPM","date":"2013-01-03","time":"1000","kind":"S","price_in":"30.35","price:_out":"30.34","gain":"0.0100"}' (length=117) 1 => string '{"ticker":"SPM","date":"2013-01-04","time":"1000","kind":"S","price_in":"30.22","price_out":"30.09","gain":"0.1300"}' (length=116)` – Rayon Feb 19 '16 at 17:16
  • and now i understand even less.. :( – Plastic Feb 19 '16 at 17:25
  • My problem i solved cause now I tried from my server and it works like a charm.. Before I was trying from "localhost" and for some reason it makes the difference – Plastic Feb 19 '16 at 17:28
  • Any error in console ? Looks good to me... – Rayon Feb 19 '16 at 17:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/103978/discussion-between-plastic-and-rayon-dabre). – Plastic Feb 19 '16 at 17:29

0 Answers0