How to pass parameters for ajax call
How to pass parameters for ajax call
kulkarni_ash
Posts: 35Questions: 8Answers: 0
I have a function like below which is working fine, now i want pass some parameters to my spring controller how can i do so
The controller is like below
[code]
@RequestMapping(value = "/displayDataAjax")
public @ResponseBody
DataTablesResponse displayDataAjax(@RequestParam
int year, @RequestParam String code) throws Exception {
//logic to send JSON here
}
[/code]
My Ajax call to populate data table,
[code]
$('#example').dataTable({
"bSort": false,
"sPaginationType": "full_numbers" ,
"bProcessing": true,
"bDeferRender": true,
"bDestroy": true,
"sAjaxSource": 'displayDataAjax',
"aoColumns": [
{
"fnRender": function ( oObj ) {
var text = "";
return text;
}
}
,
{
"fnRender": function ( oObj ) {
// alert($('#editAccess').val());
if($('#editAccess').val() == 'true'){
var text = "" + oObj.aData.airportcd + "";
return text;
}
else{
return oObj.aData.airportcd;
}
}
//,
//"mDataProp": "airportcd"
},
{ "mDataProp": "airportname" },
{ "mDataProp": "cityname" },
{ "mDataProp": "statename" },
{ "mDataProp": "countryname" },
{ "mDataProp": "transportationtypecd" },
{ "mDataProp": "istauckprovided" },
{ "mDataProp": "iscitydefault" }
]
}
);
[/code]
The controller is like below
[code]
@RequestMapping(value = "/displayDataAjax")
public @ResponseBody
DataTablesResponse displayDataAjax(@RequestParam
int year, @RequestParam String code) throws Exception {
//logic to send JSON here
}
[/code]
My Ajax call to populate data table,
[code]
$('#example').dataTable({
"bSort": false,
"sPaginationType": "full_numbers" ,
"bProcessing": true,
"bDeferRender": true,
"bDestroy": true,
"sAjaxSource": 'displayDataAjax',
"aoColumns": [
{
"fnRender": function ( oObj ) {
var text = "";
return text;
}
}
,
{
"fnRender": function ( oObj ) {
// alert($('#editAccess').val());
if($('#editAccess').val() == 'true'){
var text = "" + oObj.aData.airportcd + "";
return text;
}
else{
return oObj.aData.airportcd;
}
}
//,
//"mDataProp": "airportcd"
},
{ "mDataProp": "airportname" },
{ "mDataProp": "cityname" },
{ "mDataProp": "statename" },
{ "mDataProp": "countryname" },
{ "mDataProp": "transportationtypecd" },
{ "mDataProp": "istauckprovided" },
{ "mDataProp": "iscitydefault" }
]
}
);
[/code]
This discussion has been closed.
Replies
Also will the control to aoColumns to build the data once the call is successfull?
[code]
$('#showByTourTable').dataTable({
"bSort": false,
"sPaginationType": "full_numbers" ,
"bProcessing": true,
"bDeferRender": true,
"bDestroy": true,
"sAjaxSource": 'getAirportAvaliableByTourYear',
"fnServerParams": function ( aoData ) {
aoData.push( { "year": $('#touryear').val(), "tourCd": $('#tourcode').val()} );
},
"fnServerData": function ( sSource, aoData, fnCallback ) {
alert('Ajax call ' + aoData);
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback,
"error": alert('Error in getting data for AirportAvaliableByTourYear')
}
);
},
"aoColumns": [
{
"fnRender": function ( oObj ) {
// return 'checkBox ' + oObj;
var text = "";
// return '';
return text;
}
}
);
[/code]
but it is not building the table,
what is suppose to happen with success: fnCallback, where should the control go,
i dont see the data reaching "aoColumns" at all
what am i missing
[code]
var param = "?year="+$('#touryear').val()+"&tourCd="+$('#tourcode').val();
$('#showByTourTable').dataTable({
"bSort": false,
"sPaginationType": "full_numbers" ,
"bProcessing": true,
"bDeferRender": true,
"bDestroy": true,
"sAjaxSource": 'getAirportAvaliableByTourYear'+param,
"aoColumns": [
{
"fnRender": function ( oObj ) {
]
}
[/code]