我将如何编辑它,以便它在放入表单时接受图像,所有其他选项仅适用于不上传到服务器或数据库的图像。
请有人帮忙我环顾四周,找不到任何我理解的东西,有人可以为此添加一些代码吗?
提前致谢。
<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>
最佳答案
那是因为 <input type="file"
在执行 .serialize()
时被跳过在表格上。
有可能upload files with JavaScript , 但更容易在表单中完成:
<form action="../AdsCrease/CreateCar.php" method="post" enctype="multipart/form-data">
...
<input type="file" name="myfile" ... />
...
<button type="submit">Submit</button>
</form>
关于javascript - 在脚本中接受图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12750721/