非法调用错误jquery

时间:2015-02-27 17:21:20

标签: javascript php jquery

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,但它显示我未捕获TypeError:非法调用。请帮助!

2 个答案:

答案 0 :(得分:3)

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

     $(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);
               });
    
    
           }
        });
    

答案 1 :(得分:2)

更改变量dateFromdateTo。尝试像这样改变

$(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", { datepickerFrom:dateFrom, datepickerTo:dateTo, storeCheck: sponsers,organiser:organiser,sort:sort }, function(data) {
      alert("Data Loaded: " + data);
   });

 }
 });