jQuery-AJAX calling ASP.NET page method. How to return value back to jQuery?

前端 未结 3 1476
灰色年华
灰色年华 2021-01-13 03:08

If I use jQuery AJAX to call a specific ASP.NET page method how to have that method return a value back to the AJAX method that called it?

Update

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-13 03:32

    There are two ways to skin this cat (that I am familiar with).

    1. The ".Net Way" which involves a Web Method and a Script Manager (see here: http://geekswithblogs.net/frankw/archive/2008/03/13/asp.net-ajax-callbacks-to-web-methods-in-aspx-pages.aspx).

    2. The "Old Skool Way" which involves simply writing a response out by determining what was called. Typically you'd use a framework like MVC so going to http://www.MyWebsite.com/Object/Method/Id can map back to Object.Method(id).

    You can do this without a framework like MVC but it makes things a little more difficult and, if you go that route, you should really use an ASP.Net handler rather than an actual page (since you don't need the Aspx overhead). This is an Ashx file.

提交回复
热议问题