Call ASP.NET PageMethod/WebMethod with jQuery - returns whole page

后端 未结 8 1084
北荒
北荒 2020-11-27 02:57

jQuery 1.3.2, ASP.NET 2.0. Making an AJAX call to a PageMethod (WebMethod) returns the full/whole page instead of just the response. A breakpoint on the page method shows

8条回答
  •  北海茫月
    2020-11-27 03:20

    Most ajax scenarios I've seen really should call a web service or separate script handler, not a page. That is extremely easy to do in .net 3-5, not so easy in 2-0. Even after you figure out (if) how not to load the whole page, here are reasons not to call a page method:

    1) The page method might load less stuff than a full page load, but still far more than you need for a simple ajax call. 2) Lousy separation of responsibilities. The page is probably responsible for nicely laying stuff out, not the logic you are using in the ajax method.
    3) Maybe you need some session state, but that should still be available.

    I'm currently updating my knowledge on this subject ... I'll look for a good answer to this question in this thread, or I'll post one next week. Here is the direction I am headed

    1) Send JSON from server to client, and use javascript to update your page. - a variety of frameworks make it easy to produce JSON from the web server.
    2) JQuery makes ajax calls, json handling, and client formatting fun, instead of painful.

提交回复
热议问题