Javascript运行时错误$未定义?

Javascript运行时错误$未定义?,javascript,asp.net,Javascript,Asp.net,我总是在指向javascript函数klm()时遇到这个恼人的错误,我完全不知道为什么会出现这个错误。我已经检查了开始和结束标签,一切看起来都很好。我可能做错了什么?错误特别指向klm方法 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Dtata.aspx.cs" Inherits="Dtata" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/

我总是在指向javascript函数klm()时遇到这个恼人的错误,我完全不知道为什么会出现这个错误。我已经检查了开始和结束标签,一切看起来都很好。我可能做错了什么?错误特别指向klm方法

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Dtata.aspx.cs" Inherits="Dtata" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
      <script type="text/javascript">
          function klm() {
              $.ajax({
                  type: "POST",
                  url: "Dtata.aspx/Hello",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  data: { name: 'hello' },
                  success: function (result) {
                      response(result.d);
                      Counter() 
                  },
                  error: function (result) {
                      alert('There is a problem processing your request');
                  }
              });
          }


          function Counter() {
              $.ajax({
                  type: "POST",
                  url: "Dtata.aspx/Counter",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",

                  success: function (result) {
                      console.log(result.d);
                  },
                  error: function (result) {
                      alert('There is a problem processing your request');
                  }
              });
          }

           </script>

</head>
<body>
    <form id="form1" runat="server">
   <input id="btnGetTime" type="button" value="Show Current Time" onclick = "klm()" />
    <div>
    </div>



    </form>


</body>
</html>

函数klm(){
$.ajax({
类型:“POST”,
url:“Dtata.aspx/Hello”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
数据:{name:'hello'},
成功:功能(结果){
答复(结果d);
计数器()
},
错误:函数(结果){
警报(“处理您的请求时出现问题”);
}
});
}
函数计数器(){
$.ajax({
类型:“POST”,
url:“Dtata.aspx/Counter”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(结果){
console.log(result.d);
},
错误:函数(结果){
警报(“处理您的请求时出现问题”);
}
});
}

您需要包括jQuery。您的脚本使用jQuery函数(
$.ajax()
)请参见:

我在html页面中没有看到jQuery的导入,如下所示:您需要包含jQuery,错误指向klm函数而不是计数器函数的原因是因为加载时它首先命中了klm函数。