繁体   English   中英

Ajax无法调用asp.net Web方法

[英]ajax not working to call asp.net web method

我在ajax调用中调用asp.net Web方法。 Web方法如下所示

[WebMethod()]
public static int DropDownIndexChanged(string selectedText)
{
   int a = 5; // This is just to test
   return a;
}

在我的ajax调用中,我正在下拉列表中发送选定的值,其ID为DropDown ,如下所示

$.ajax({
              type: "POST",
              url: "FindFines.aspx/DropDownIndexChanged",
              data: { "selectedText":"+$("#DropDown option:selected").text()+"},
              success: function (data) {
                    alert("Success");
              }
});

但是没有调用函数。 请指导我正确的方法。 谢谢。

我认为您的问题是"+$("#DropDown option:selected").text()+"

var value = $("#DropDown option:selected").text();
$.ajax({
              type: "POST",
              url: "FindFines.aspx/DropDownIndexChanged",
              data: { "selectedText": value },
              success: function (data) {
                    alert("Success");
              }
});

请更换

 [WebMethod()] 

 [WebMethod]

 data: { "selectedText":"+$("#DropDown option:selected").text()+"}

  data: '{selectedText: "' + $("#DropDown option:selected").text() + '" }'

暂无
暂无

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

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