2015-05-04 71 views
1

我面临以下问题:每当我点击button时,alert显示undefinedAjax与asp.net aspx返回未定义

Web方法:

[WebMethod] 
    public static string getTest() 
    { 
     return "testing success"; 
    } 

阿贾克斯脚本

<script type="text/javascript"> 
     function getTest() { 
      $.ajax({ 
       type: "POST", 
       url: "main.aspx/getTest", 
       data: "{}", 
       datatype: "json", 
       contenttype: "/application/json; charset=utf-8", 
       success: function (msg) { 

        alert(msg.d); 

       }, 
       error: function (data) { 
       } 
      }); 
     } 
    </script> 
+0

contenttype:“/ application/json; charset = utf-8”从应用程序的开始处删除/ – Mairaj

回答

1

datatype应该dataTypecontenttype应该contentType。也从"/application/json; charset=utf-8"开始"/application/json; charset=utf-8"

$.ajax({ 
      type: "POST", 
      url: "main.aspx/getTest", 
      data: "{}", 
      dataType: "json", 
      contentType: "application/json; charset=utf-8", 
      success: function (msg) { 

       alert(msg.d); 

      }, 
      error: function (data) { 
      } 
     }); 
+0

男人你救了我的一天...一直在这花很多时间感谢很多。 –

+1

@ConvictMoody请标记为答案,如果它解决了你的问题。 – Mairaj