Firstly, I am a novice web developer working with JavaScript.
I am trying to set up a form where a user can add an image of themselves for their profile. However, when testing the code and selecting an image the value returned is undefined. For some reason it is not acknowledging the selected file.
Here is my code:
HTML
<form id="pic_form" action="#" class="wizard-big" enctype="multipart/form-data">
<h1 style="font-size:0.9vw">Image</h1>
<fieldset>
<div class="row">
<div class="col-xs-12">
<img style="height:30%; width:30%" src="img/default_pic.jpg">
<br/><br/>
<div class="form-group">
<label style="font-size:0.8vw">Change Image</label>
<input id="PlayerPic" name="PlayerPic" type="file" class="form-control" style="font-size:0.7vw; height:10%">
</div>
<div class="form-group" style="visibility: hidden">
<label>Player ID</label>
<input id="PlayerID" name="PlayerID" type="text" class="form-control" readonly>
</div>
</div>
</div>
</fieldset>
</form>
JavaScript(Client side)
$.post( "/player_pic", $("#pic_form").serialize(),
JavaScript(Server side)
app.post('/player_pic', function(req, res) {
console.log('Adding player picture...........................');
console.log('Pic = ' + req.body.PlayerPic);
console.log('ID = ' + req.body.PlayerID);
});
These are the results that I'm getting:
Adding player picture...........................
Pic = undefined
ID = 1532947080817
I have looked around and can't find a solution as to why when I select an image from a local folder in the form, it's being returned as undefined.
Any help would be very much appreciated here :)
Thanks