Move fnServerData & fnServerParams to the new AJAX method?
Move fnServerData & fnServerParams to the new AJAX method?
vman
Posts: 35Questions: 3Answers: 0
I'm working on upgrading to the new datatables and I'm having some major trouble trying to upgrade, I just wanted to know how exactly I should be handling this.
Below is the original code that I am trying to update:
"sAjaxSource": ajaxSession,
"fnServerParams": function(aoData) {
aoData.push({
"name": "action",
"value": '' + inventoryAction + ''
}, {
"name": "hotelid",
"value": '' + hotelID + ''
}, {
"name": "startDate",
"value": '' + dateStart + ''
}, {
"name": "endDate",
"value": '' + dateEnd + ''
}, {
"name": "startDateLoad",
"value": '' + dateStartLoad + ''
}, {
"name": "endDateLoad",
"value": '' + dateEndLoad + ''
}, {
"name": "weekdayLoad",
"value": '' + weekDay + ''
}, {
"name": "loadRooms",
"value": '' + loadRooms + ''
}, {
"name": "loadPrice",
"value": '' + loadPrice + ''
}, {
"name": "sellLoadPrice",
"value": '' + sellLoadPrice + ''
}, {
"name": "restrictions",
"value": '' + restrict + ''
}, {
"name": "addlDisc",
"value": '' + addlDisc + ''
}, {
"name": "comm",
"value": '' + comm + ''
}, {
"name": "stopSale",
"value": '' + stopSale + ''
}, {
"name": "shopped",
"value": '' + shopped + ''
}, {
"name": "username",
"value": '' + sessuname + ''
}, {
"name": "guid",
"value": '' + sessguid + ''
});
},
"fnServerData": function(url, aoData, fnCallback, oSettings) {
if (url != 'null') {
oSettings.jqXHR = $.ajax({
"url": url,
"data": aoData,
"type": "POST",
"dataType": 'jsonp',
"success": function(json) {
var len = json.aaData.length;
for (var e = 0; e < len; e++) {
var total = parseInt(json.aaData[e]['soldRooms']) + parseInt(json.aaData[e]['available']);
var disc = 0;
if (parseFloat(json.aaData[e]['regPrice']) != 0)
disc = 100 - Math.floor((json.aaData[e]['salePrice'] / json.aaData[e]['regPrice']) * 100);
json.aaData[e]['totalRooms'] = total;
json.aaData[e]['discount'] = disc;
}
fnCallback(json);
},
"cache": false
});
}
},
From here I've been messing with the AJAX command in DataTables but I seem to get the same results of nothing. Any help will be awesome, I'll let anyone know if I figured it out as well.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Looks like it should work. Can you link to a test case showing the issue so we can take a look please?
Allan
Hey Alan, sadly I cannot. But this method does work, but I am trying to upgrade it to the 1.10 method using strictly AJAX. For example instead of "sAjaxSource" I would use...
Same goes for the server params and the server data functions.
If you are updating the above code for 1.10 (which you don't have to, the old style shout still work), use
ajax
as a function. Alternatively you could useajax.dataSrc
andajax.data
to manipulate the data received from, and sent to, the server.Allan
While the old style does still work, I wanted to upgrade what I had over so I figure it would be worth it to everything as a whole. I've tried using the ajax method before, but it would sit at processing as if no request could be made. So I wanted help formatting it from what I have to the new style for 1.10.
The
ajax.dataSrc
andajax.data
documentation is probably your best starting point in that case.Allan
Alright, I'll just start messing with things, thanks for your time!