簡體   English   中英

為什么.post jquery函數不能在我的代碼中運行?

[英]Why isn't the .post jquery function working in my code?

我嘗試使用jQuery的jquery函數,但它不起作用

這很奇怪。 我在js文件中添加了一些警報,但是當我點擊按鈕(id =“gettotalnutrients”)時,js文件中沒有任何警報發生。

這是我抓取js文件的數據(並顯示數據)的地方:

        <div id="feedback"></div>
    <br />
    <form id="form_date_nutrient_getter" action="account-overview.php" method="POST">
    Select a start date: <input id="datestart" type="text" name="beginday_calendar"><br />
    Select a end date: <input id="dateend" type="text" name="endday_calendar"><br />
                    <input type="button" id="gettotalnutrients" value="Get the total nutrients" ><br /><br /><br /><br /><br /><br /><br />
    </form>
    </div>

js文件:

$('#gettotalnutrients').click(function(){
           alert('test');
           var datestart = $('#datestart').val();
           alert(datestart);
           var dateend = $('#dateend').val();
           alert(dateend);
           $.post('getTotalNutrients.php',(beginday_calendar: datestart, endday_calendar: dateend), function(data){
            $('#feedback').text(data);
                });
                                });

將你的click()函數包裝在$(document).ready()或類似的東西中:

$(document).ready(function() {
  $('#gettotalnutrients').click(function(){
    // the rest of your code goes here
  });
});

另外,你在js控制台中看到任何錯誤嗎?

您是否嘗試將括號括起來{

  $(function(){
      $('#gettotalnutrients').click(function(){
       //remaining code  

         $.post('getTotalNutrients.php',{ beginday_calendar: datestart, endday_calendar: dateend}, function(data){
                $('#feedback').text(data);
              });

           });            
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM