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.
使用ajax将文件上传到服务器上传目录,图像没有上传到上传目录。我收到“连接重置”的错误。请让我知道我在下面的代码中所犯的错误。我在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.
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');
}
});
});
});
1 个解决方案
#1
0
Move your var formData = new FormData($('form')[0]);
outside of $(document).ready(function(){
something like the below added linesvar formData = new FormData($('form')[0]); $(document).ready(function() { $("#formID").on('submit', function(event) {
移动你的var formData = new FormData($('form')[0]); $(document).ready之外的函数(function(){类似于下面添加的行var formData = new FormData($('form')[0]); $(document).ready(function(){$(“ #formID“)。on('submit',function(event){
#1
0
Move your var formData = new FormData($('form')[0]);
outside of $(document).ready(function(){
something like the below added linesvar formData = new FormData($('form')[0]); $(document).ready(function() { $("#formID").on('submit', function(event) {
移动你的var formData = new FormData($('form')[0]); $(document).ready之外的函数(function(){类似于下面添加的行var formData = new FormData($('form')[0]); $(document).ready(function(){$(“ #formID“)。on('submit',function(event){