0

I am trying to upload the following form

<form id="filesend" enctype="multipart/form-data" method="post" action="upload.php"> Choose the file you want to send <br> <input name="file" type="file"><br><input type="submit"></form>

using the following jquery code

<script>
$('document').ready(function() { 
var options= { target:'#close'}
$('#filesend').submit( function (){
$(this).ajaxSubmit(options);
          return false;         
})})
</script>

but nothing happens and the form submits like a normal html form and navigates to upload.php and yes I have included the plugin. Any ideas as to where I might be going wrong.

Edit

I just noticed something intresting. If i go through chrome's debugger and watch every step of the execution the file gets uploaded to the database twice. But going through it without any breakpoints results in it only being uploaded once.

1

4 Answers 4

1

The problem is with this part:

$(#filesend).submit( function (){
    $(this).ajaxSubmit(options);
    return false;         
})

The selector should be a string, so: $('#filesend') - note the single quotes (you can also use double quotes).

Without them it's trying to pass the value of the variable named #filesend to the function; I'm not sure that's a valid variable name, so it would probably throw an error - checking your browser's developer tools console would tell you if an error had been thrown because of it.

Sign up to request clarification or add additional context in comments.

1 Comment

No that doesnt fix it although i hadn't noticed that either... anything else i may have missed?
1

File upload is NOT possible through ajax. You can upload file, without refreshing page by using IFrame. you can check further details here:

http://www.ajaxf1.com/tutorial/ajax-file-upload-tutorial.html

With XHR2, File upload through AJAX is supported. for example through FormData object, but unfortunately it is not supported by all/old browsers.

1 Comment

According to the plugin documentation it supports file uploads, likely using an <iframe> in the background when necessary.
0

I don't think you can submit files using Ajax. JQuery based file upload plugins allows you to 'nicely' show the file upload input box.

Comments

0

There is syantax problem in your code

look closer here

$('#filesend').submit( function (){
$(this).ajaxSubmit(options);
          return false;         
})});

The selector needs to windup ins string i.e. '#filesend'.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.