Skip to content
Advertisement

Problem with link to file, javascript, xml, object FormData

I have a function that allows you to select an attachment, but I can’t get the file paths from it to send it to php.

Can it be done without using forms and reloading the entire page?

I update my function, but they return: from=s@p.pl&temat=da&msg=da&usser=lalala&file=[object FormData]

What I can do with it? I need link to file.

Function like this:

JavaScript

Advertisement

Answer

It looks to me like you’re using FormData incorrectly here. If you take a look at this part of your code:

JavaScript

Unless you serialize them somehow, binary files can’t be uploaded as URL parameters, they have to be sent as part of the request body. I think you’re close, and there’s just two changes you need to make here:

First, your URL parameters need to be tacked onto the URL itself:

JavaScript

You then need to pass your FormData into send():

JavaScript

If you need some more help using FormData, check the MDN docs.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement