c# - JavaScript type: "GET" not getting to controller from jQuery dataTable -


this weird (to me)! can controller making straight ajax call when try make same call inside datatable code block, execution never gets in controller.

i'm new jquery datatables have other instances in code base use examples. cannot figure out wrong here.

this code gets controller:

getassets = function () {     // converting array of int(s) string     var ids = selectedids.tostring();     // setting data controller parameters     var odata = { "facids": ids, "type": selectedtype };      $.ajax({         url: "api/services/getassetsbyids",   //  call gets controller         type: "get",         data: odata,         datatype: "json",         success: function (result) {             var = result;         }        }); } 

this code not controller:

initselectableassettable = function () {      jqueryvar.jselectableassettable.datatable({         "bpaginate": false,         "bprocessing": true,         "bautowidth": true,         "aocolumns": [             { "mdataprop": "assetid", "bsortable": true },             { "mdataprop": "assetname", "bsortable": true }         ],         "aocolumndefs": [         { "mdataprop": null, "sdefaultcontent": " ", "atargets": [-1] }         ],         "sdom": '<"top">rt<"bottom"><"clear">',         "olanguage": {             "semptytable": "no assets found."         },         "sajaxsource": $.baseurl("api/services/getassetsbyids"),         "fnserverdata": function (ssource, aodata, fncallback) {             var ids = selectedids.tostring();             var odata = { "facids": ids, "type": selectedtype };             $.ajax({                 url: ssource, //  never gets controller                 type: "get",                 data: odata,                 datatype: "json",                 success: fncallback,                 error: function (jqxhr, textstatus, errothrown) {                     alert(jqxhr.responsetext);                 }             });         }     }); } 

i've tried replacing ssource url no avail. can please tell me doing wrong?

controller code:

[httpget] public list<assetdto> getassetsbyids(string facids, string type) {     list<assetdto> assets = new list<assetdto>();     list<int> ids = array.convertall<string, int>(facids.split(','), new converter<string, int>(convert.toint32)).tolist();     iassetservice service = new assetservice();     if(type.equals("rack"))     {         assets = service.getrackassetsbyids(ids);     } else {         assets = service.getassetsbyids(ids);     }     return assets; } 

i know doesn't directly address issue, try using first snippet works , defining/initializing datatable in success function.

for instance, in success: function (data, textstatus, jqxhr) {, assign data parameter data property of datatable.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -