使用AJAX将jquery数组传递给PHP
问题描述:
having a bit of an issue with sending a jQuery array to a PHP file. I've looked at similar questions on here, but mine has other elements to the data variable being sent. Here's the code:
var data = 'type='+e+'&offset=' + all_dates_offset + '&filters=' + filters;
$.ajax({
url: "pos_jobs.php",
type: "POST",
cache: false,
data:data,
dataType:"json",
success: function(html){
//Do Something
}
});
For the data, 'e' and 'all_dates_offset' are standard variables, whereas 'filters' is an array. On the PHP side of things, I was hoping I could just use something like $_POST['filters'][0], but that is returning a null value.
Any ideas?
Thanks.
答
$.ajax({
url: "pos_jobs.php",
type: "POST",
data: {type: e, offset: all_dates_offset, filters: filters},
dataType:"json"
}).done(function(data) {
//do something
});
答
use below
$.ajax({
url: "pos_jobs.php",
type: "POST",
cache: false,
data:{'type':e,'offset':all_dates_offset,'filters':filters},
dataType:"json",
success: function(html){
//Do Something
}
});