C# 对WebMethod的Ajax调用失败
因此,我尝试对C# 对WebMethod的Ajax调用失败,c#,ajax,request,webmethod,C#,Ajax,Request,Webmethod,因此,我尝试对WebMethod(ASP.NETC#)执行AJAX请求。为了解决我的问题,我已经研究了很多话题,但我什么也找不到 这是我目前的代码: <script type="text/javascript"> function mostrarMensaje() { $.ajax({ type: "POST", url: "index.aspx/devolverMensaje"
WebMethod
(ASP.NETC#)执行AJAX请求。为了解决我的问题,我已经研究了很多话题,但我什么也找不到
这是我目前的代码:
<script type="text/javascript">
function mostrarMensaje() {
$.ajax({
type: "POST",
url: "index.aspx/devolverMensaje",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success:
function (msg) {
alert('El mensaje devuelto por el servidor es: ' + msg);
},
error:
function (msg) {
alert(msg.status + " " + msg.statusText);
}
});
}
</script>
响应状态为0。有人能帮我吗?提前谢谢 问题已经解决了。故障是我的,我没有看到按钮只是在显示消息之前刷新页面
谢谢你的提醒 这是令人惊讶的。当我从控制台调用javascript函数时,FireBug向我显示ajax返回的消息。我想问题一定出在别的地方。我注意到,当我按下按钮调用函数时,刷新页面。
namespace Test
{
public partial class Formulario_web1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod()]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static String devolverMensaje() {
return "pepe";
}
}
}