簡體   English   中英

在PHP中提取JQuery POST參數

[英]Extracting JQuery POST parameters in PHP

我正在嘗試使用JQuery將一組復選框傳遞給PHP。 我正在使用“ 使用JSON將多個復選框項傳遞到PHP文件並查詢數據庫”中的代碼,是否應該在這個問題下發布此代碼?

復選框是日歷中每月中的每一天的復選框。 值是一個月中的整數天

<td><input name="check[]" value="4" type="checkbox">4</td>
<td><input checked="yes" name="check[]" value="7" type="checkbox">7</td>

復選框位於表格的表格中。

<form id="checkboxes">
<table id="calendarId" class="calendar"> 

我使用Jquery將復選框傳遞給PHP:

   $("#calendarId").load($.post("calendar.php",{check: $("form#checkboxes").serialize()}));

Firebug顯示post參數中有一個復選框列表。 我檢查生成此示例的兩天分別是7和21,這在代碼中是可以辨認的。

check   check%5B%5D=7&check%5B%5D=21
Source
check=check%255B%255D%3D7%26check%255B%255D%3D21

我的問題是我無法在PHP中提取這些值。

parse_str($_POST['check'], $checkboxes); 

返回一個空字符串,循環遍歷POST數組也是如此:

foreach($_POST as $key=>$val){
    $test .= $key . "; " . $value . "; ";
}

嘗試循環$ _POST ['check']會產生一個錯誤,我認為這意味着$ _POST ['check']為空。

完整頁面位於http://www.genomics.liv.ac.uk/shereMuseum/calendar1.html

我還嘗試過在發布之前將復選框打包到數據結構“復選框”中:

        var checkboxes = new Array();
        $("input[name='check[]']:checked").each(function(){checkboxes.push($(this).val());});

要么

        $.each($("input[name='check[]']:checked"),function() {
                checkboxes.push($(this).val());
        });

但隨后Firebug將POST參數報告為:

undefined   undefined
undefined   undefined
Source
undefined=undefined&undefined=undefined

如有任何建議,我將不勝感激。 哈利

不知道為什么要使用$('#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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM