0

Is there a way in ASP.net to fetch data from database using Jquery Ajax Method. I know that i can easily access the data by creating a webservice and get it from there using Ajax. What I want to know is that how can I get the data from simple class methods which accesses the database rather than creating a webservice.

2 Answers2

0

One way can be is to write a HTTPHandler and call that handler using Jquery to retrieve the data.

Deepansh Gupta
  • 593
  • 4
  • 9
0

Check this out for a super-easy (lazy) way of doing a return straight from a public method defined in your aspx.cs file:

asp.net web forms json return result

Example shows putting [WebMethod] and [ScriptMethod(ResponseFormat = ResponseFormat.Json)] attributes on top of the method allows you to call directly from ajax client side request. Worth considering securing this method though to prevent calls from elsewhere!

Community
  • 1
  • 1
Luke Baughan
  • 4,658
  • 3
  • 31
  • 54