我想用多個文件使用Post jQuery
方法,但在嘗試查看數組結果時出現undefined index
錯誤。試圖尋找答案,但仍然無法做到這一點。什麼是這樣做的正確方法。下面是我的代碼示例中,使用jquery POST一個數組
HTML
<input type="file" name="others[]" multiple="multiple">
jQuery的
$(document).ready(function(){
$("#submit").click(function(){
var array = [$("input[name='others']").val()],
others = {
"upload[]": array,
},
id = $("input[name='id']").val();
$.post('updated-file-others.php',
{
others : others,
id : id
}, function(data){
$("#result_post").html(data);
});
});
});
PHP
if(isset($_POST['id'])){
$id = $_POST['id'];
$others = array($_FILES['upload']['name']);
}
echo "<pre>"; print_r($others); echo "</pre>";
id的值是正確的。它會發布id值。如果我使用id例如id ='others'。我是否也需要放置'[]'。 – Amran