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:非法调用。请帮助!
答案 0 :(得分:3)
$(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);
});
}
});
答案 1 :(得分:2)
更改变量dateFrom
和dateTo
。尝试像这样改变
$(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);
});
}
});