2015-05-04 85 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