首页 > Web开发 > 详细

JQuery ajax调用asp.net的webMethod

时间:2016-10-19 17:05:49      阅读:210      评论:0      收藏:0      [点我收藏+]

在vs2010中,用JQuery ajax调用asp.net 2.0的  webMethod 方法时,怎么都调不出来,原来和3.5 有点出入。

3.5中,无需特殊设置,可以直接用$.ajax调用在aspx.cs中,访问级别public,静态的,标记为【webmethod】的方法。

 

aspx.cs:

using System.Web.Services;
[WebMethod]
public static string PollCount()
{
    ……    return getResultHTML(ds2);

}


 
jquery:
<div id="divAnswers" runat="server">
</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: "voteresult.aspx/PollCount",
                data: "{}",
                dataType: "json",
                success: function (msg) 
                {
                    $("div[id$=divAnswers]").fadeOut("fast").html(msg.d).fadeIn("fast", function () { animateResults(); });
                }
            });
    });
    function animateResults() {
        $("div[id$=divAnswers] img").each(function () {
            var percentage = $(this).attr("val");
            $(this).css({ width: "0%" }).animate({ width: percentage }, ‘slow‘);
        });
    }  
</script>

技术分享

 

.net2.0 Web.config:

<!--JQuery ajax调用asp.net的webMethod问题  2.0-->
<httpModules>
  <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>

 

JQuery ajax调用asp.net的webMethod

原文:http://www.cnblogs.com/gycnet/p/5977518.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!