简体   繁体   English

ASP.NET Ajax无法正常工作

[英]ASP.NET ajax do not work

I do not know why this do not work(can not call SendValues method).There is no error raise up. 我不知道为什么这不起作用(无法调用SendValues方法)。没有错误提示。 Can anyone help me ? 谁能帮我 ? Thank you very much! 非常感谢你!

The html page some thing like below: html页面如下所示:

 <script language="javascript" type="text/javascript">
     $(function () {
         $("#Button1").click(function () {
             $.ajax({
                 type: "POST",
                 url: "WebForm1.aspx/SendValues",
                 data: { 'Code': '1026' },
                 contentType: "application/json; charset=utf-8",
                 dataType: "json",
                 success: function (json) {
                     alert(json.d);
                 },
                 failure: function () {
                     alert("Sorry,there is a error!");
                 }
             });

         });
     });
 </script>

The c# code Some thing like: C#代码类似:

 public partial class WebForm1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    [WebMethod]
    public static string SendValues(string Code)
    {
        string contects = string.Empty;

        return contects;
    }

}

我已经通过将数据{{'Code':'1026'}修改为“ data:{'Code':'1026'}”解决了这个问题

数据应指定为

data: '{ Code:["1026"]}'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM