[英]Extracting JQuery POST parameters in PHP
I am trying to pass a group of checkboxes to PHP using JQuery. 我正在尝试使用JQuery将一组复选框传递给PHP。 I am using the code from Passing multiple checkbox items to PHP file using JSON and querying a DB Should I post this under that question?
我正在使用“ 使用JSON将多个复选框项传递到PHP文件并查询数据库”中的代码,是否应该在这个问题下发布此代码?
The checkboxes are one for each day in the month in a calendar. 复选框是日历中每月中的每一天的复选框。 Values are integer days of the month
值是一个月中的整数天
<td><input name="check[]" value="4" type="checkbox">4</td>
<td><input checked="yes" name="check[]" value="7" type="checkbox">7</td>
The checkboxes are within a table in a form. 复选框位于表格的表格中。
<form id="checkboxes">
<table id="calendarId" class="calendar">
I use Jquery to pass the checkboxes to PHP: 我使用Jquery将复选框传递给PHP:
$("#calendarId").load($.post("calendar.php",{check: $("form#checkboxes").serialize()}));
Firebug shows that a list of checked boxes is in the post parameters. Firebug显示post参数中有一个复选框列表。 The two days I checked to generate this example were 7 and 21 which are discernible in the code.
我检查生成此示例的两天分别是7和21,这在代码中是可以辨认的。
check check%5B%5D=7&check%5B%5D=21
Source
check=check%255B%255D%3D7%26check%255B%255D%3D21
My problem is that I am unable to extract these values in PHP. 我的问题是我无法在PHP中提取这些值。
parse_str($_POST['check'], $checkboxes);
returns an empty string, as does looping over the POST array: 返回一个空字符串,循环遍历POST数组也是如此:
foreach($_POST as $key=>$val){
$test .= $key . "; " . $value . "; ";
}
Trying to loop over $_POST['check'] generates an error which I assume means that $_POST['check'] is empty. 尝试循环$ _POST ['check']会产生一个错误,我认为这意味着$ _POST ['check']为空。
The complete page is at http://www.genomics.liv.ac.uk/shereMuseum/calendar1.html 完整页面位于http://www.genomics.liv.ac.uk/shereMuseum/calendar1.html
I have also tried to pack the checkboxes into a data structure "checkboxes" before posting: 我还尝试过在发布之前将复选框打包到数据结构“复选框”中:
var checkboxes = new Array();
$("input[name='check[]']:checked").each(function(){checkboxes.push($(this).val());});
or 要么
$.each($("input[name='check[]']:checked"),function() {
checkboxes.push($(this).val());
});
But then Firebug reports the POST parameters as: 但随后Firebug将POST参数报告为:
undefined undefined
undefined undefined
Source
undefined=undefined&undefined=undefined
I would be very grateful for any suggestions. 如有任何建议,我将不胜感激。 Harry
哈利
Not sure why you are using $('#calendarId').load(...), but have you tried doing it like 不知道为什么要使用$('#calendarId')。load(...),但是您是否尝试过像
$.ajax({
type: 'POST',
url: 'calendar.php',
data: $('#checkboxes').serialize(),
success: function(response) {
// handle the response here
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.