Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
执行代码时出现Javascript运行时错误_Javascript_Html_Asp.net_Asp.net Mvc - Fatal编程技术网

执行代码时出现Javascript运行时错误

执行代码时出现Javascript运行时错误,javascript,html,asp.net,asp.net-mvc,Javascript,Html,Asp.net,Asp.net Mvc,我想从一个窗体中获取两个值,并在按下按钮时将其传递给控制器 到目前为止,我掌握的代码是: <div id="date"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <p>@Resources.Resourc

我想从一个窗体中获取两个值,并在按下按钮时将其传递给控制器

到目前为止,我掌握的代码是:

  <div id="date">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <p>@Resources.Resources.Date: <input type="text" id="datepicker"></p>
  <script name="select_date" id="select_date">

  $(function getInfo() {
      intDate = Date;
      var userName = $('#search_employee').val();
      $("#datepicker").datepicker({
          //defaultDate: "+1w",
          changeMonth: true,
          changeYear: true,
          numberOfMonths: 1,
          minDate: "01/01/2008"
      });
      $("button.action").click(function () {
          //console.log(select_date);
          var date = $('#datepicker').val().toString();
          $.ajax('EmployeeDate', {
              data: {
                  strUserName: userName,
                  strDate: date
              },
              success: function (data, textStatus, jqXHR) {
                  //this will happen on success of request
                  $('#DataUser').html(data);
              },
              error: function () {
                  console.log("error handler when ajax request fails... ");
              },

          });
      });
  });
</script>
<button onclick="getInfo()" id="userButton">@Resources.Resources.ButtonFind</button>
<br>

@Resources.Resources.Date:

$(函数getInfo(){ intDate=日期; var userName=$(“#搜索_员工”).val(); $(“#日期选择器”)。日期选择器({ //默认日期:“+1w”, 变化月:对, 变化年:是的, 月数:1, minDate:“01/01/2008” }); $(“button.action”)。单击(函数(){ //console.log(选择日期); var date=$('#datepicker').val().toString(); $.ajax('EmployeeDate'{ 数据:{ strUserName:用户名, 日期 }, 成功:函数(数据、文本状态、jqXHR){ //这将在请求成功时发生 $('#DataUser').html(数据); }, 错误:函数(){ log(“ajax请求失败时的错误处理程序…”); }, }); }); }); @Resources.Resources.ButtonFind
`

当我执行代码时,会出现以下错误:

0x800a1391-JavaScript运行时错误:“getInfo”未定义

代码里写了什么

谢谢

编辑

 $(function () {
      intDate = Date;
      var userName = $('#search_employee').val();
      $("#datepicker").datepicker({
          //defaultDate: "+1w",
          changeMonth: true,
          changeYear: true,
          numberOfMonths: 1,
          minDate: "01/01/2008"
      });
      $("button.action").click(function () {
          //console.log(select_date);
          var date = $('#datepicker').val().toString();
          $.ajax('EmployeeDate', {
              data: {
                  strUserName: userName,
                  strDate: date
              },
              success: function (data, textStatus, jqXHR) {
                  //this will happen on success of request
                  $('#DataUser').html(data);
              },
              error: function () {
                  console.log("error handler when ajax request fails... ");
              },

          });
      });
  });
</script>
    <button class="action"    type="button">@Resources.Resources.ButtonFind</button>
<br>
$(函数(){
intDate=日期;
var userName=$(“#搜索_员工”).val();
$(“#日期选择器”)。日期选择器({
//默认日期:“+1w”,
变化月:对,
变化年:是的,
月数:1,
minDate:“01/01/2008”
});
$(“button.action”)。单击(函数(){
//console.log(选择日期);
var date=$('#datepicker').val().toString();
$.ajax('EmployeeDate'{
数据:{
strUserName:用户名,
日期
},
成功:函数(数据、文本状态、jqXHR){
//这将在请求成功时发生
$('#DataUser').html(数据);
},
错误:函数(){
log(“ajax请求失败时的错误处理程序…”);
},
});
});
});
@Resources.Resources.ButtonFind


当我按下按钮时,什么也没发生。。谢谢

尝试添加不带$()的函数

像这样

function getInfo() {
  intDate = Date;
  var userName = $('#search_employee').val();
  $("#datepicker").datepicker({
      //defaultDate: "+1w",
      changeMonth: true,
      changeYear: true,
      numberOfMonths: 1,
      minDate: "01/01/2008"
  });
  $("button.action").click(function () {
      //console.log(select_date);
      var date = $('#datepicker').val().toString();
      $.ajax('EmployeeDate', {
          data: {
              strUserName: userName,
              strDate: date
          },
          success: function (data, textStatus, jqXHR) {
              //this will happen on success of request
              $('#DataUser').html(data);
          },
          error: function () {
              console.log("error handler when ajax request fails... ");
          },

      });
  });
}

尝试添加不带$()的函数

像这样

function getInfo() {
  intDate = Date;
  var userName = $('#search_employee').val();
  $("#datepicker").datepicker({
      //defaultDate: "+1w",
      changeMonth: true,
      changeYear: true,
      numberOfMonths: 1,
      minDate: "01/01/2008"
  });
  $("button.action").click(function () {
      //console.log(select_date);
      var date = $('#datepicker').val().toString();
      $.ajax('EmployeeDate', {
          data: {
              strUserName: userName,
              strDate: date
          },
          success: function (data, textStatus, jqXHR) {
              //this will happen on success of request
              $('#DataUser').html(data);
          },
          error: function () {
              console.log("error handler when ajax request fails... ");
          },

      });
  });
}
这是一个范围问题。 您有两个选择:

1.将全局范围内的函数移到$(document.ready()之外


函数getInfo(){
...
};
@Resources.Resources.ButtonFind
2.管理$(document.ready()中的click侦听器

$(函数(){
函数getInfo(){
...
};
$('button#userButton')。单击(函数(e){
getInfo();
})
});
@Resources.Resources.ButtonFind
这是一个范围问题。 您有两个选择:

1.将全局范围内的函数移到$(document.ready()之外


函数getInfo(){
...
};
@Resources.Resources.ButtonFind
2.管理$(document.ready()中的click侦听器

$(函数(){
函数getInfo(){
...
};
$('button#userButton')。单击(函数(e){
getInfo();
})
});
@Resources.Resources.ButtonFind

只是
函数getInfo(){
(但是在函数中有一个
.click()
处理程序是没有意义的-而且你似乎没有一个按钮带有
class=“action”。当你点击带有
id=“userButton”的按钮时,你想做什么`?我想将所选的日期和用户名发送到控制器,以在sql Server中执行存储过程然后我想您的意思是将
$(function getInfo(){
更改为
$(function(){
并更改
$('button.action')。单击(function(){
更改为
$('.\35; userButton')。单击(function(){
并从按钮的htmlJust
函数getInfo(){
中删除
onclick=“getInfo()”
(但是在函数中有一个
。click()
处理程序是没有意义的-而且您似乎没有一个按钮带有
class=“action”)。当你用
id=“userButton”``点击按钮时,你想做什么?我想把日期和所选用户名发送到控制器,在sql Server中执行存储过程。那么我想你的意思是更改
$(function getInfo(){
$(function(){
和更改
$(“button.action”)。单击(function(){
$(“#userButton”)。单击(function(){
并从按钮的html中删除
onclick=“getInfo()”
$(function() {

    function getInfo() {
        ...
    };


    $('button#userButton').click(function(e){
        getInfo();
    })

  });
<button id="userButton">@Resources.Resources.ButtonFind</button>