load page, user enters search, then hits "search" button
load page, user enters search, then hits "search" button
FredFlintstone
Posts: 24Questions: 0Answers: 0
ok, i wrestled with servicestack and got this all working. now need to do the same with mvc4 and it's like drawing teeth. how can something so simple be so difficult?
This discussion has been closed.
Replies
with the same controller, commenting out any method parameters,
this works:
[code]
table.dataTable({
"bPaginate": false,
"bSort": true,
"bFilter": false,
"bServerSide": true,
"bDestroy": true,
"bJQueryUI": true,
"sAjaxSource": WebApiBaseURL + "/SearchResults",
});
[/code]
same controller, with parameters (searchTerms) enabled, returning exactly the same data,
this doesn't work. no data is rendered by the datatable.
[code]
table.dataTable({
"bPaginate": false,
"bSort": true,
"bFilter": false,
"bServerSide": true,
"bDestroy": true,
"bJQueryUI": true,
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
url: WebApiBaseURL + "/SearchResults",
data: searchTerms,
type: 'GET',
dataType: 'json',
timeout: 15000,
success: function (data) {
//alert(data.aaData[0]);
},
error: function (xhr, textStatus, errorThrown) {
debugger;
var res = xhr.responseText;
alert("err" + errorThrown);
}
});
}
});
[/code]
the controller method is hit each time, and returns EXACTLY the same data, in the same format. has anyone any idea what i'm doing wrong?
That looks static - unless you are assigning the variable before the draw is performed. Also you aren't submitting the values DataTables needed for server-side processing (aoData in your above function). If you want to add extra parameters, I'd suggest using fnServerParams rather than fnServerData .
Allan
anyway, got it finally. it was simply this:
success: fnCallback,
in the ajax call. fnServerData requires that unlike sAjaxSource (apparently!) :)
many thanks allan...