0
我有這個腳本,所以它去../AdsCreate/CreateCar.php讀取表單並插入到數據庫中,並加載到一個特定的div,這一切工作正常。腳本捕捉圖像
我有一個問題,表單的一部分是上傳圖像,現在它不這樣做我已經被告知它是因爲下面的腳本序列化數據,並沒有這樣做基於文件。
這是腳本。
<script type="text/javascript">
jQuery(document).ready(function($) {
$("#Submit").click(function() {
var url = "../AdsCreate/CreateCar.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#myForm").serialize(), // serializes the form's elements.
success: function(html){ $("#right").html(html); }
});
return false; // avoid to execute the actual submit of the form.
});
});
</script>
這裏是我的形式
<form method="post" enctype="multipart/form-data" id="myForm">
<table class="default1" style="width: 100%" align="center">
<tr>
<td class="content1" colspan="3"><h3><b>Car Ads</b></h3></td>
</tr>
<tr>
<td class="content1" width="70%">Make: <input type="text" name="name"></td>
<td class="content1" width="15%">Model: <input type="text" name = "email"></td>
<td class="content1" width="15%">Year: <input type="text" name = "phone"></td>
</tr>
<tr>
<td class="content1" colspan="3">Main Photo: <input type="file" name="photo"></td>
</tr>
<tr>
<td class="content1" colspan="3"><input type="submit" value="Upload" id="Submit"></td>
</tr>
</table>
</form>
我怎樣才能改變劇本,所以我可以上傳也有一個文件上傳表單?
您還可以使用jQuery的形式上傳文件:
製作
AJAX調用不能上傳文件。通常的解決方法是創建一個隱藏的iframe並在那裏進行正常的提交。 –
如何添加上面給出的腳本,對此很新穎,謝謝。 –