Skip to content Skip to sidebar Skip to footer

How To Pass Array Of Objects As Parameters On Ajax Post

I have the following array object [{'site':'88333','event':'TEST','event_window':'4th April - 4th April','monitoring_start':'10-Apr-2016','monitoring_end':'10-Apr-2016'}] I am try

Solution 1:

Try this..

var params = [{"site":"88333","event":"TEST","event_window":"4th April - 4th April","monitoring_start":"10-Apr-2016","monitoring_end":"10-Apr-2016"}];
    console.log(params);
    $.ajax({
        url : '../../api/netcool/add-event',
        data : {params:params},
        type: 'POST',
        error : function (data, textStatus, jqXHR) {
            if(data.statusText != "abort")
                console.log(data);
        },
        success : function (data) { 
            console.log(data);
        }
    });

And in ../../api/netcool/add-event method.. you can acccess the parameter by

print_r($_REQUEST['params'][0]);
echo $_REQUEST['params'][0]['site'];

Post a Comment for "How To Pass Array Of Objects As Parameters On Ajax Post"