我有 jQuery 代码:
$(document).ready(function() {
answers = new Array();
answers[0] = new Array();
answers[0]['question_id'] = 12;
answers[0]['answer_id'] = 32;
answers[1] = new Array();
answers[1]['question_id'] = 55;
answers[1]['answer_id'] = 132;
answers[2] = new Array();
answers[2]['question_id'] = 987;
answers[2]['answer_id'] = 1112;
$.ajax({
type: "POST",
url: "collect.php",
data: {answers: answers},
dataType: "json",
beforeSend:function(){
// Do something before sending request to server
},
error: function(jqXHR, textStatus, errorThrown){
alert(errorThrown);
},
success: function(data){
alert('success!');
}
});
});
现在,这应该工作吗?根据我在寻找代码示例时发现的内容。问题是,我不知道如何在我的 PHP 文件中收集数据。我的意思是,它是一个 $_POST[],但是然后呢?如何收集 $result[0]['question_id'] 和所有其他数据?
非常感谢提前,
卡尔·卡尔森