SOURAV
SOURAV

Reputation: 314

Send Json data to controller

I am sending some data as cat_id into here

$.get('/ajax3?cat_id=' +cat_id,function(data){});

I want to send multiple data like cat_id, sub_id How can I do this:

<script>
$("#cat3").on('click',function (e) {
//console.log(e);

var cat_id=document.getElementById('cat').value;
var sub_id=document.getElementById('sub').value;

    $.get('/ajax3?cat_id=' +cat_id,function(data)
    {
        $('#sub1').empty();
        $.each(data,function(index,subcatObj)
        {
            $('#sub1').append('<li>'+subcatObj.section+'</li>');
        })

    });
});

In my controller i get cat_id that i send. Now I want to pass sub_id how do I do this???

Upvotes: 0

Views: 65

Answers (1)

Vit Kos
Vit Kos

Reputation: 5755

Well, that sounds pretty simple. You just add sub_id to the query string:

$("#cat3").on('click',function (e) {
//console.log(e);

var cat_id=document.getElementById('cat').value;
var sub_id=document.getElementById('sub').value;

    $.get('/ajax3?cat_id=' +cat_id + '&sub_id=' + sub_id  ,function(data)
    {
        $('#sub1').empty();
        $.each(data,function(index,subcatObj)
        {
            $('#sub1').append('<li>'+subcatObj.section+'</li>');
        })

    });
});

Then you can just use the Input Facade to get the parameter in your controller:

Input::get('sub_id')

Upvotes: 1

Related Questions