简体   繁体   English

使用Ajax从代码隐藏调用的方法返回未定义

[英]Method called from codebehind with ajax return undefine

I want to get value from codebehind that then I call it using ajax, but I got nothing, in succes it just show undefine , here the code 我想从代码背后获取价值,然后我使用ajax对其进行调用,但我一无所获,成功的只是显示undefine,这里的代码

function PopMensaje() {

            $.ajax({
                type: "POST",
                url: "/WebForms/Modulo Tramites/ProcesosTramites/frmIniciarTramite.aspx/metodoajax",
                data: '{}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    alert("retorno "+result.d);
                },
                error: function () {
                    alert('Ocurrio un error');

                }
            });

on calling show 在通话节目中

    };

and this the function in codebehind 这是代码背后的功能

  [WebMethod]
  public static string metodoajax(){
        return "123";
    }

on calling shows "retorno undefine".I expect it shows "retorno 123" 在通话中显示“ retorno undefine”。我希望它显示“ retorno 123”

What I'm doing wrong? 我做错了什么? How to fix this? 如何解决这个问题?

You function works fine. 您的功能正常。 I think that your are missing jQuery in your webform and the closing brace for your javascript function: 我认为您在Webform中缺少了jQuery,并且在javascript函数中没有了以下括号:

        <head runat="server">
          <script src="Scripts/jquery-2.1.4.min.js" type="text/javascript"></script>
       </head>

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

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