Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对WebMethod的Ajax调用失败_C#_Ajax_Request_Webmethod - Fatal编程技术网

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";
        }
    }
}