2
How to upload image using Jquery?
This is a question that has been chasing me for a long time, I hope you can help me.
Well, I’ve been researching and I saw that you have a plugin for this, ajaxForm. However I can not find structure to use it, the page itself has some examples but I had the ability not to understand how to do.
There’s also Formdata that I don’t know where it’s from, so I’m going to do some research. If you can help me with one of those two, which is more viable and easier. I’ll be very grateful.
Thank you in advance!
(A great way to help me would be with the structure of what to give example, so I can learn by looking at how it is done).
In the date append you pass 2 parameters. What would be the first and the second? indicates me some document to read or it is simple thing and you tell me
– Pedro Soares
The first parameter would be the name so that I can retrieve in the programming (example
$_FILES['fileimagem']
) and the second is the content of the file to send to the server which in case is the chosen image !!! Any doubt we are there.– user46523
@Pedrosoares more on the subject in Formdata.append()
– user46523
I hope you can still help me. I have a problem :( When I put: var data = new Formdata(); data.append('fileimage', $('#fileimage')[0]. files[0]); The ajax request stops working, if I remove and pass another value in date it works normal. know what it can be?
– Pedro Soares
Relationship
<input type="file" name="fileimagem" id="fileimagem" />
with$('#fileimagem')
is the relationship with Jquery taking and accessing that input tag type file (which is the image) but, in Jquery you need to inform$('#fileimagem')[0].files[0]
in the second parameter to work. I don’t really know how your code is but, the relation is this.– user46523
I understood, but my code is locking in js when I create a new Formdata(); ?
– Pedro Soares
I did some testing and it’s actually this line that’s catching data.append('fileimage', $('#fileimage')[0]. files[0]);
– Pedro Soares
Let’s go continue this discussion in chat.
– Pedro Soares