JQuery Ajax calls ASP. WebMethod

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.