How can i get specific value from my ajax response


How can i get specific value from my ajax response
I am trying to make a PHP profile edit form where user can upload their picture as their profile picture so I use this
my ajax response contain message about the information about the upload form. now my question is how can i save the image upload path to database.
or I have another form on the same page where I have a hidden field where I try to get the path of upload image from the data
response message.
data
I try
$('#message').change(function()
var filepath = $('div#message>div.alert>p>a.filepath').attr('href');
$('input#profile_img').val(filepath);
);
my hidden field of another form in same page which can same all information to database.
<input id="profile_img" type="hidden" name="profile_img" value="">
Picture upload HTML:
<form id="upload-image-form" action="" method="post" enctype="multipart/form-data">
<div id="image-preview-div" style="display: none">
<label for="exampleInputFile">Selected image:</label>
<br>
<img id="preview-img" src="noimage">
</div>
<div class="form-group">
<input type="file" name="file" id="file" required>
</div>
<button class="btn btn-primary" id="upload-button" type="submit" disabled>Upload image</button>
</form>
<br>
<div class="alert alert-info" id="loading" style="display: none;" role="alert">
Uploading image...
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
</div>
</div>
</div>
<div id="message"></div>
Image upload handler
<?php
if ( isset($_FILES["file"]["type"]) )
?>
@piyush yes profile pic upload is optional but I solve this by change my success function
– Firefog
1 hour ago
@can you help me with multiple file upload ? and save all path to comma separated on db?
– Firefog
1 hour ago
1 Answer
1
I have change the success section like and it works
success: function(data)
$('#loading').hide();
$('#message').html(data);
var filepath = $('div#message>div.alert>p>a.filepath').attr('href');
$("input#profile_img").val(filepath);
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Is that profile picture functionality is in two parts like first user upload picture and you show the uploaded picture by ajax response and then user click on submit button to save it in db?
– piyush
1 hour ago