0
這裏是我的html不確定的指數使用Ajax時上傳文件
<form id="uploadimage" name="form" action="" enctype="multipart/form-data">
<input type="file" name="files" id="file" />
<input type="submit" value="Upload">
</form>
這裏是我的Javascript代碼
$(document).ready(function (e) {
$("#uploadimage").submit(function(e) {
e.preventDefault();
$("#message").empty();
$('#loading').show();
$.ajax({
url: "ajax_php_file.php", // Url to which the request is send
type: "POST", // Type of request to be send, called as method
data:new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
contentType: false, // The content type used when sending data to the server.
cache: false, // To unable request pages to be cached
processData:false, // To send DOMDocument or non processed data file it is set to false
success: function(data) // A function to be called if request succeeds
{
$('#loading').hide();
$("#message").html(data);
}
});
});
});
我想用ajax上傳文件。 JavaScript正在將數據正確地發送到php文件,但php代碼顯示錯誤未定義的索引文件。那麼,你能說出我在做什麼錯嗎?
這裏的PHP文件中的代碼
<?php
$filetype=$_FILES["files"]["type"];
?>
什麼'var_dump($ _ FILES)'show? – Barmar
它顯示 數組(0){} – user2663856
檢查Web控制檯的網絡選項卡,看看是否在您執行AJAX請求時發送'FormData'參數。 – Barmar