請幫我修改代碼。我需要從ajax這樣的陣列:car1 [汽車的顏色] ['關於汽車的故事']。 但我只能得到:car1 ['關於汽車的故事']。 我已經閱讀了很多技巧,但沒有成功。我是php的begginer。 非常感謝具體的答案:)下面的腳本如何通過post,ajax,php,jquery從FORM獲取多維數組?
// HTML smaller version
<form class= "ajax2" action="formInsertCar.php" method="POST">
<input type="submit" value="Save All">
<div>
<select name="car1[]" size="1">
<?php $opt = new CarOptions;?>
</select>
<textarea name="car1[]"></textarea>
</div>
<div>
<select name="car2[]" size="1">
<?php $opt = new CarOptions;?>
</select>
<textarea name="car2[]"></textarea>
</div>
</form>
// JavaScript, ajax for FORM
$('form.ajax2').on('submit', function() {
var that = $(this),
url = that.attr('action'),
type = that.attr('method'),
data = {};
that.find('[name]').each(function(index, value) {
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
// here I want to result like: car1['color of car']['story about car'];
// but I can get only: car1['story about car']
});
$.ajax({
url: url,
type: type,
data: data,
success: function(response) {
$('.success').html(response);
}
});
return false;
});
非常感謝你:) :) :)。它的工作原理不會改變html :) :) :) – Tomi