I have looked into many posts on this subject so please do not mark it as duplicate as there are no straight answers provided. But if you truly believe that I may have missed something, which provides cross-browser support (IE8+ too) do indicate which one and then mark it as duplicate.
I want to use JQuery AJAX to post files and some text data and access that info in PHP on the server side using $_FILES and $_POST. I am able to do so without AJAX. The problem is when I start using AJAX.
Here is a simple example:
HTML:
<form id="upload_form" method="POST" enctype="multipart/form-data">
<input type="text"/>
<input type="file"/>
<button type="submit">Submit</button>
</form>
JAVASCRIPT:
var ser_data = $('#upload_form').serialize();
...on submit... {
...
upload_promise = $.ajax({
url: 'upload1.php',
dataType: 'html',
type: 'POST',
data: ser_data,
});
...
}
Well, we all know that .serialize will serialize only the text fields input and file is not readable by JS, etc. I am not trying to do anything fancy here. I just need a mechanism to access $_FILES and $_POST in PHP on the server side with the file name and the text data entered on the client side. The actual form has more fields (more file and text types) but this is the crux of the problem.