function search()
{
  var dateFrom = $("#datepickerFrom").val();
  var dateTo = $("#datepickerTo").val();
  var sponsers = $("#storeCheck").val();
  var organiser = $("#organiser").val();
  var sort = $("#sort").val();
  $(document).ready(function() {
    $.post("searchEvents.php", {
        datepickerFrom: datepickerFrom,
        datepickerTo: datepickerTo,
        storeCheck: sponsers,
        organiser: organiser,
        sort: sort
      },
      function(data) {
        alert("Data Loaded: " + data);
      });
  });
}


我试图将变量从jquery传递到php,但它向我显示Uncaught TypeError:非法调用。请帮忙!

最佳答案

为什么将$(document).ready()放在search()函数中?
更改变量名称,例如未定义datepickerFrom


尝试这个:

 $(document).ready(function(){
        function search()  {
        var dateFrom = $("#datepickerFrom").val();
        var dateTo = $("#datepickerTo").val();
        var sponsers = $("#storeCheck").val();
        var organiser = $("#organiser").val();
        var sort = $("#sort").val();

        $.post("searchEvents.php", { dateFrom:dateFrom, dateTo: dateTo, storeCheck: sponsers,organiser:organiser,sort:sort },function(data) {
         alert("Data Loaded: " + data);
           });


       }
    });

关于javascript - 非法调用错误jQuery,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28770768/

10-09 22:40