jquery - friendly url causes ajax to not get the correct url -


i converted url user friendly, problem is, caused ajax not work properly: instead of returning json, responds text/html; charset=utf-8, idea?

localhost/home/ticket?tab=0

to

localhost/home/ticket/0

jquery datatable

self.$('#tblticket').datatable({     "bdestroy": true,     "bserverside": true,     "sajaxsource": '/home/ticket/ajaxhandler',     "fnserverparams": function (aodata){      aodata.push( { "name": "sstatus", "value": status } );  }, 

routers

routes.maproute(    name: "ticketroute",    url: "ticket/{tab}",    defaults: new { controller = "ticket", action = "index", tab = urlparameter.optional } ); 

update 1

if change router this, works, url localhost/home/ticket/index/0. router interferes ajax call, idea? want url localhost/home/ticket/0 , still able ajax call, have no idea, can done?

        routes.maproute(             name: "ticketroute",             url: "ticket/index/{tab}",             defaults: new { controller = "ticket", action = "index", tab = urlparameter.optional }         ); 

in mvc4 version did following:

  1. created method in controller datatables can access

    [httpget] public actionresult getrecords(jquerydatatableparammodel param) {     #region viewmodel binding totalrecords count, pagination , search     list<vm_datatable_tablename> model;     int totalrecords = 0;     using (dbentities db = new dbentities())     {         model = mapper.map(db.getrecords(), new list<vm_datatable_tablename>()); //using automapper viewmodel bindings         totalrecords = model.count();     }     #endregion      #region filtration/pagination     var filtered = ***filter depending on needs***      var displayed = filtered.skip(param.idisplaystart).take(param.idisplaylength);     #endregion      #region convert result string array json conversion/trim excess white space reduce size of result     ienumerable<string[]> result = new list<string[]>();     result = displayed              .select(s => new string[] {                 (!string.isnullorempty(convert.tostring(s.id))) ? s.id.tostring().trim() : string.empty,                 (!string.isnullorempty(s.val_1)) ? s.val_1.trim() : string.empty,                 (!string.isnullorempty(s.val_2)) ? s.val_2.trim() : string.empty,                 (!string.isnullorempty(s.val_3)) ? s.val_3.trim() : string.empty              });     #endregion      return json(new     {         secho = param.secho,         itotalrecords = totalrecords,         itotaldisplayrecords = filtered.count(),         aadata = result     },     jsonrequestbehavior.allowget); } 
  2. in jquery datatables initialisation:

    $('#tblticket').datatable({     "bdestroy": true,     "bserverside": true,     "sajaxsource": '@url.content("~/home/ticket/getrecords")', //server inserted url     "fnserverdata": function data(ssource, aodata, fncallback) {         $.ajax({             "datatype": "json",             "contenttype": "application/json; charset=utf-8",             "type": "get",             "url": ssource,             "data": aodata,             "success":                 function (msg) {                     //whatever other actions want data                     fncallback(msg);                 },             "failure":                 function (xmlhttprequest, textstatus, errorthrown) {                     alert(xmlhttprequest.status);                     alert(xmlhttprequest.responsetext);                 }         });     } }); 

'@url.content("")' friendly when using mvc areas.

these series of articles helped me lot when first started using plugin.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -