2013-05-18 3 views
0

Я практикую вызов jquery ajax. Что происходит, когда я запускаю свой проект, он дает ошибку INTERNAL SERVER ERROR 500. Что означает эта ошибка и как я могу столкнуться с этой ошибкой?Asp.net jquery ajax call

Я создал пример проекта, в котором я добавил этот код:

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

Определите вашу функцию Public ... для доступа из Jquery как этот

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