How to write ajax function in c# -


the below function how write in c# backend. post method via list.

$(function () {     $.ajax({         type: "post",         url: "default.aspx/getcustomers",         data: '{}',         contenttype: "application/json; charset=utf-8",         datatype: "json",         success: onsuccess,         failure: function (response) {             alert(response.d);         },         error: function (response) {             alert(response.d);         }     }); }); 

you should have customer model in backend, can try this:

    [httppost]      public string getcustomers()      {          list<customers> listcustomers = new list<customers>();            /* list of customers returned              database or picking data*/          customersviewmodel model = new customersviewmodel(){                 customers = listcustomers;             }              return json(model, jsonrequestbehavior.allowget);                } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -