【发布时间】:2018-04-08 03:05:05
【问题描述】:
我正在使用这个SO question 来处理我使用复选框的过滤器搜索。
这是JS
$('input[type="checkbox"]').on('change', function (e) {
var data = {},
fdata = [],
loc = $('<a>', { href: window.location })[0];
$('input[type="checkbox"]').each(function (i) {
if (this.checked) {
if (!data.hasOwnProperty(this.name)) {
data[this.name] = [];
}
data[this.name].push(this.value);
}
});
// get all keys.
var keys = Object.keys(data);
var fdata = "";
// iterate over them and create the fdata
keys.forEach(function(key,i){
if (i>0) fdata += '&'; // if its not the first key add &
fdata += key+"="+data[key].join(',');
});
$.ajax({
type: "get",
url: "/ajax/get",
data: {
"_token": "{{ csrf_token() }}",
"fdata": fdata
},
success: function (response) {
$('#d2d-results').html(response);
}
});
if (history.pushState) {
history.pushState(null, null, loc.pathname + '?' + fdata);
}
});
现在我尝试将 fdata 的值传递给 PHP。
在 PHP 上,我得到变量 echo $_GET['fdata']; 的这个值:
discount=Y&brand=BR0006,BR0003
我想要什么
$discount="Y";
$brand="BR0006,BR0003";
这样可以吗?
【问题讨论】:
-
将
fdata保存为对象 -
嗨@Hikarunomemory 你能给我举个例子吗?
-
你试过
$_GET['fdata']['discount'];吗? -
刚刚尝试并得到错误:
Warning: Illegal string offset 'discount' in -
这里有一个类似的帖子link
标签: php query-string