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并在那里进行正常的提交。 –
如何添加上面给出的脚本,对此很新颖,谢谢。 –