0

I had an array like the following

var a = [
        {
            "start":"2015-01-12T00:00:00.000Z",
            "allDay":false,
            "promotion_option":"banner"
        },
        {
            "start":"2015-01-13T00:00:00.000Z",
            "allDay":false,
            "promotion_option":"banner"
        }
    ];

And I post that object of array like the following using JQuery Ajax

$.ajax({
    type: method,
    url: url,
    data: a,
    success: function(res) {
        var message = res.mesg;

        if (message) {
            $('.flash').html(message).fadeIn(300).delay(250).fadeOut(300);
        };
    }
});

In my controller when I try dd(Input::all()), it's just return

array(1) {
  ["undefined"]=>
  string(0) ""
}

So, How I can get the value of what I had posted?

2
  • stackoverflow.com/questions/8890524/… look here, maybe, adding {...} for data will help Commented Jan 6, 2015 at 9:05
  • send an object like this: {a:a}. Commented Jan 6, 2015 at 9:15

2 Answers 2

2

You need to pass data as Object and use dataType:'json' as you are using res.mesg in success callback like this,

$.ajax({
    type: method,
    url: url,
    data: {a:a},//<== use object here
    dataType:'json',// add this, as you are using res.mesg
    success: function(res) {
        var message = res.mesg;
        if (message) {
            $('.flash').html(message).fadeIn(300).delay(250).fadeOut(300);
        };
    }
});
Sign up to request clarification or add additional context in comments.

Comments

1

try JSON.stringify(a) which will convert it to something like this

"[{"start":"2015-01-12T00:00:00.000Z","allDay":false,"promotion_option":"banner"},{"start":"2015-01-13T00:00:00.000Z","allDay":false,"promotion_option":"banner"}]"

Note that it converts it into a string in your backend whereever you recieve the httprequest you just have to keep that in mind.Hope it helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.