javascript - 在脚本中接受图像

标签 javascript html

我将如何编辑它,以便它在放入表单时接受图像,所有其他选项仅适用于不上传到服务器或数据库的图像。

请有人帮忙我环顾四周,找不到任何我理解的东西,有人可以为此添加一些代码吗?

提前致谢。

<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/

相关文章:

javascript - 如何对 div 元素进行沙箱处理?

javascript - 如何对复杂的 promise 链进行单元测试?

javascript - 匹配链接中的页码

php - 更改 CSS onclick 函数 javascript

Javascript:单击主体中除其中一个元素之外的任何位置

html - 动态加载页面内容及其CSS - 如何防止因为尚未加载CSS而跳转?

javascript - html页面中的文本突出显示

javascript - jQuery 中的选项过滤器

javascript - 如何在 javascript/jquery 的日期选择器中禁用日历中的过去日期?

html - 为什么 HTML 要求多个空格在浏览器中显示为单个空格?