使用ajax将文件上载到服务器上载目录。(File upload to server upload directory by using ajax. The image is not getting

编程入门 行业动态 更新时间:2024-10-22 23:36:07
使用ajax将文件上载到服务器上载目录。(File upload to server upload directory by using ajax. The image is not getting uploading to upload directory; getting the error of connection reset)

使用ajax将文件上传到服务器上传目录,图像没有上传到上传目录。 我收到“连接重置”的错误。 请让我知道我在下面的代码中所犯的错误。 我在netbeans IDE中的站点根目录中创建了上载目录。

<body> <form method="post" action= "upload"> <input type=file id="media" name=media> <input type="submit"> </form> </body>

jquery代码将图像上传到上传文件夹。

$(document).ready(function(){ $(form).on('submit',function(event){ event.preventDefault(); var formData = new FormData($('form')[0]); $.ajax({ type:'POST', url:'upload', data :formData, processData:false, contentType:false, success:function() { alert('File uploaded'); } }); }); });

File upload to server upload directory by using ajax the image is not getting uploading to the upload directory. I'm getting the error of "connection reset". Please let me know the mistake I am doing in the below code. I created the upload directory in the site root in the netbeans IDE.

<body> <form method="post" action= "upload"> <input type=file id="media" name=media> <input type="submit"> </form> </body>

jquery code to upload the image to upload folder.

$(document).ready(function(){ $(form).on('submit',function(event){ event.preventDefault(); var formData = new FormData($('form')[0]); $.ajax({ type:'POST', url:'upload', data :formData, processData:false, contentType:false, success:function() { alert('File uploaded'); } }); }); });

最满意答案

移动你的var formData = new FormData($('form')[0]); 在$(document).ready(function(){ 类似下面添加的行 var formData = new FormData($('form')[0]); $(document).ready(function() { $("#formID").on('submit', function(event) {

Move your var formData = new FormData($('form')[0]); outside of $(document).ready(function(){ something like the below added lines var formData = new FormData($('form')[0]); $(document).ready(function() { $("#formID").on('submit', function(event) {

更多推荐

本文发布于:2023-08-06 14:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1450240.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器   文件   目录   upload   File

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!