2013-05-18 138 views
0

我正在練習jquery ajax調用。發生什麼事情是,當我運行我的項目時,它給內部服務器錯誤500.這個錯誤意味着什麼,我怎麼會遇到這個錯誤?Asp.net jquery ajax調用

我創建了我加入這個代碼示例項目:

namespace sample 
{ 
    public partial class jqAjaxcall : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      if (!IsPostBack) 
       GetDateTime(); 
     } 
     [WebMethod] 
     private static string GetDateTime() 
     { 
      return DateTime.Now.ToString(); 
     } 
    } 
} 

我的aspx代碼文件:

<script type="text/javascript" src="Library/js/jquery-1.9.1-min.js"></script> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
      // Add the page method call as an onclick handler for the div. 
      $("#Result").click(function() { 
       $.ajax({ 
        type: "POST", 
        url: "jqAjaxcall.aspx/GetDateTime", 
        data: "{}", 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 
        success: function (msg) { 
         // Replace the div's content with the page method's return. 
         $("#Result").text(msg.d); 
        } 
       }); 
      }); 
     }); 
    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div id="Result"> 
     Click here for the time.</div> 
    </form> 
</body> 
</html> 

回答

1

定義函數的公共...從jQuery的這樣

訪問
[WebMethod] 
//define function as public.... 
     public static string GetDateTime() 
     { 
      return DateTime.Now.ToString(); 
     }