[英]Ajax request is not working with ASP.NET page method
I tried so many example codes and neither works. 我尝试了很多示例代码,但均无济于事。 Ajax call simply does not return anything.
Ajax调用根本不返回任何内容。 There is no alert popup.
没有警报弹出窗口。
This is the ajax code : 这是ajax代码:
<script src="Scripts/jquery-1.10.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "POST",
url: "mysqlcall.aspx/Testing",
contentType: "application/json; charset=utf-8",
data: {""},
dataType: "json",
success: function (data) {
alert("idkbro");
// $("#testing").text(response.d);
},
failure: function (response) {
alert(response.d);
}
});
});
</script>
And this is the call page : 这是呼叫页面:
public partial class mysqlcall : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string Testing()
{
return "asdlasldalsdl";
}
}
I'm running it on latest version of IIS and using asp.net C# webforms with routing. 我在最新版本的IIS上运行它,并使用带路由的asp.net C#Webforms。 mysqlcall.aspx is not routed but it doesn't matter I tried it with a routed page.
mysqlcall.aspx没有被路由,但是没关系我尝试了路由页面。 Any help would be appreciated.
任何帮助,将不胜感激。
Edit : Thanks to @wazz the problem was in the 编辑:感谢@wazz,问题出在
url: "mysqlcall.aspx/Testing",
instead it has to begin with a slash like : 相反,它必须以斜杠开头:
url: "/mysqlcall.aspx/Testing",
Add the WebMethod
attribute and make the method static
: 添加
WebMethod
属性并使该方法static
:
[WebMethod]
public static string Testing()
{
return "asdlasldalsdl";
}
You can also remove data
from the ajax call, or remove the quotes. 您还可以从ajax调用中删除
data
,或删除引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.