Reproduced in this article: http://www.cnblogs.com/zengxiangzhan/archive/2011/01/16/1936938.html
In vs2010, when using jquery ajax to call the WebMethod method of the ASP. NET 2.0, it's not going to work out, and the original and 3.5 are somewhat out. 3.5, without special settings, can be called directly with $.ajax in Aspx.cs, access level public, static, labeled "WebMethod" method. Aspx.cs:using System.Web.Services; [Webmethod]public static string Pollcount () {... return getresulthtml (DS2);} jquery:<div id= "divanswers" runat= "se RVer "></div><script src=" Scripts/jquery-1.4.4.min.js "type=" Text/javascript "></script>< Script language= "javascript" type= "Text/javascript" > $ (document). Ready (function () {var imgpoll = new Image ( ); IMGPOLL.SRC = ' style/red-bar.png '; $.ajax ({type: "POST", ContentType: "Application/json", url: "Vot Eresult.aspx/pollcount ", Data:" {} ", DataType:" JSON ", Success:function (msg {$ ("div[id$=divanswers]"). FadeOut ("Fast"). HTML (MSG.D). FadeIn ("Fast", function () {A Nimateresults (); }); } }); }); function Animateresults () {$ ("Div[id$=divanswers] img"). each (function () {var percentage = $ (this). att R ("Val"); $ (this). CSS ({width: "0%"}). Animate ({width:percentage}, ' slow '); }); } </script>
A good similar article:
Http://www.cnblogs.com/fanyong/p/3463701.html
http://blog.csdn.net/gulijiang2008/article/details/6234940
Get rid of ashx/asmx, use Jquery.ajaxwebservice request Webmethod,ajax processing more concise
Developing an AJAX program under WebForm requires a generic handler (*.ASHX) or Web service (*.asmx), and each Ajax request is built with one such file, so that if there are many AJAX programs in a project, There is bound to be a bunch of. ashx or. asmx, although the program itself is not a hindrance, but that pile of files seems to always feel very hurt. So can you throw away these. ashx and. asmx, choose a more concise way to do AJAX programs.
The answer is yes, that is: WebMethod.
Article Address: http://www.mysjtu.com/page/M0/S231/231122.html