0

I know this seems like already asked question, but I did research and none of the solutions worked for me. I have an javascript array like this:

[from: "2016-04-01", to: "2016-04-14"]

And I'm sending it via AJAX on the same page, like so:

data.date=date;
            console.log(data.date);
            $.ajax({
                url: "",
                type: "POST",
                dataType: "JSON",
                data: data,
                async: true,
                success: function (data) {

                }
});

And I put var_dump($_POST['date']); at the beginning of my page. When I look at Network took of my browser I can see that request is sent, and my page is listed within Network pages, but $_POST['date'] array is NULL. And I did put this JS code within $(document).ready();, so that cannot be the issue. I just want to get value of this javascript array into php variable.

1
  • Try to pass JSON.stringify(data) to the data param. Commented Apr 15, 2016 at 8:41

1 Answer 1

1

Shouldn't it be [{from: "2016-04-01", to: "2016-04-14"}] ? Isn't it an object inside the array?

Sign up to request clarification or add additional context in comments.

1 Comment

You are absolutely right. I made mistake by declaring var data=new Array() instead of var data={};

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.