load page, user enters search, then hits "search" button

load page, user enters search, then hits "search" button

FredFlintstoneFredFlintstone Posts: 24Questions: 0Answers: 0
edited March 2013 in General
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?

Replies

  • FredFlintstoneFredFlintstone Posts: 24Questions: 0Answers: 0
    ok, enough of the ranting :)

    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?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    > data: searchTerms

    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
  • FredFlintstoneFredFlintstone Posts: 24Questions: 0Answers: 0
    "aren't submitting the values DataTables needed for server-side processing" - no, they were getting passed in correctly. (i should have shown the searchTerms)

    anyway, got it finally. it was simply this:

    success: fnCallback,

    in the ajax call. fnServerData requires that unlike sAjaxSource (apparently!) :)

    many thanks allan...
This discussion has been closed.