使用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) {
更多推荐
发布评论