[英]File upload through ajaxform not working
我正在嘗試通過AJAX調用(&PHP)上傳圖像。 我正在使用ajaxform插件來執行此操作,但是,顯然,當我提交表單時,“文件”輸入值未傳遞到php腳本。 這是我的HTML和JS:
<form action="upload_file.php" method="post" enctype="multipart/form-data" id="select-image">
<input type="file" name="image" size="30"/> <input type="submit" name="upload" value="Upload" />
</form>
<script>
var options = {
success: showResponse // post-submit callback
};
// bind form using 'ajaxForm'
$('#select-image').ajaxForm(options);
// post-submit callback
function showResponse(responseText, statusText, xhr, $form) {
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
'\n\nThe output div should have already been updated with the responseText.');
}
</script>
為了測試upload.php包含:
<?php
if(isset($_POST['upload'])){
var_dump($_FILES);
}
?>
什么時候提交表格,我回來的就是:
Array(
[image]=>
)
難道我做錯了什么? 我什至可以通過Ajaxform插件上傳圖像嗎? 請提出建議。
謝謝。
嘗試在var選項中添加'cache:false'。
var options = {
cache : false,
success: showResponse // post-submit callback
};
為我工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.