我有一個頁面,有一堆的勾號框,這些都是用名稱=「一個數字」標識的。 當單擊一個按鈕時,我有一個JavaScript函數,可以創建一個新數組,其中打勾的方框數量。這會發送到'test.php'頁面。javascript新陣列 - > php陣列
它返回:
Array
(
[data] => [null,"47284","47282","47281","47280","47279","47278","47277","47276","47269"]
)
當我嘗試和爆炸這陣,我得到一個數組,字符串轉換錯誤。
我在做什麼錯?
我需要將這些數字分開,以便我可以爲每個數據執行SQL查詢。
JavaScript代碼:
<script>
var selected = new Array();
function showMessage() {
var selected = Array();
$('input:checked').each(function() {
selected.push($(this).attr('name'));
});
var answer = confirm('Are you sure you want to send these emails again?');
if(answer) {
var jsonString = JSON.stringify(selected);
$.ajax({
url: "../../test.php",
type: "POST",
data: {data : jsonString},
success: function(data){
alert(data);
}
})
}
}
</script>
<SCRIPT language="javascript">
$(function(){
// add multiple select/deselect functionality
$("#selectallsent").click(function() {
$('.yes').prop('checked', this.checked);
});
$("#selectallprogress").click(function() {
$('.no').prop('checked', this.checked);
});
// if all checkbox are selected, check the selectall checkbox
// and viceversa
$(".yes").click(function(){
if($(".yes").length == $(".yes:checked").length) {
$("#selectallsent").prop("checked", "checked");
} else {
$("#selectallsent").removeAttr("checked");
}
});
$(".no").click(function(){
if($(".no").length == $(".no:checked").length) {
$("#selectallprogress").prop("checked", "checked");
} else {
$("#selectallprogress").removeAttr("checked");
}
});
});
</script>
test.php的代碼:
<?
print_r($_POST);
?>
我知道,我需要做的事情更多test.php的頁面上,但我想知道那是什麼。
你應該打印'data' post var。 –
如果你試圖爆炸一個數組,那麼你的問題。爆炸將一個字符串變成一個數組。 – Rooster
那麼我需要做什麼來拆分這個數組呢?即時通訊疲憊和困惑,但我真的需要在我睡覺之前完成這件事。在此先感謝您的幫助 – fightapilotdean