Welcome Guest, Not a member yet? Register   Sign In
Ajax data, file upload
#1

[eluser]yorvik[/eluser]
Hello I use AJAX to add my form data to my database I do it like this:

Code:
$.ajax({
                    url: 'url..',
                    type: 'POST',
                    data: {
                        artID: vartID,
                        categoryID: vCategoriID,
                        price = vPrice,

                    },
                    success: function(data) {
                        $('#error').text(data);
                    }

These are all the value's of my <input type="text"> fields.
But how do I add the data of
<input type="file" name="myFile" />. So if I also want to send a file to php script how does that work. Or is this not possible?

Thanks in advance.
#2

[eluser]Georgi Budinov[/eluser]
If you are using JQuery you can look at this library for form submition.
Submiting a file through ajax is a tough task ... there are some solutions .. the one I suggested is using hidden iframe.
#3

[eluser]Agustín Villalba[/eluser]
To send a file input you need a "multipart" form, and it 's impossible to send multipart forms with AJAX, it's simple, if it were possible, JavaScript would have direct access to your local file system and that would be a very huge security hole.
So, if you have a multipart form, right now, in this moment, you can't send it by AJAX, may be in the future if technology changes.
#4

[eluser]Georgi Budinov[/eluser]
@Agustín Villalba ... you are right that with an ajax request a file cannot be sent but still there is a solution doing the same job!
#5

[eluser]Agustín Villalba[/eluser]
If I'm not worng, that was the question made by yorvik, how can he add the file input to the AJAX request, and it is impossible. Another thread is that you can send a form with an input file and by AJAX check the status of the file uploading, but technically, it is impossible to send a file by AJAX.
Please, if you know that there is a solution doing the same job, let us know it!
Thanks!
#6

[eluser]Georgi Budinov[/eluser]
There is no point in argueing with you! Just check this http://jquery.malsup.com/form/#file-upload




Theme © iAndrew 2016 - Forum software by © MyBB