Skip to content
Advertisement

$_POST remains null when posting through ajax with formData

This is the form:

JavaScript

Ajax/Javascript:

JavaScript

php:

JavaScript

Output:

JavaScript

The var_dumps basically output nothing, these are the notices shown for the php file:

JavaScript

The final scope of this is to be able to send an email with an attachment using $_FILES for the file, and $_POST for the text data. But first I need to figure out why $_POST is not containing fd or formData. PS: Im not sure if var fd = JSON.stringify(object); is necessary or not for this scenario.

Any help would be greatly appreciated as I have been stuck on this for a while now.

Also, ‘Request Payload’ is returning [object Object]

Advertisement

Answer

The FormData object has to be the value of the data: option, it can’t be nested inside another object.

JavaScript

Then in PHP you can access the parameters with $_POST['mail_id'], $_POST['brand'], and $_FILES['attachment'].

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