I'm trying to store image in a variable and stringify it in json to pass it through ajax method. But getting error in storing it and stringify it in json format. The dynamic table i am generating like this from where we pick the image id 'flImage' and store it in a variable user
$("#pdfFormInsideTblRight").after("<table class='table table-bordered'><thead class='thead-inverse'><tr><th class='text-left'>Properties</th>" +
"<th>Detail</th></tr></thead>" +
"<tr><td class='text-left'><strong>Product Group</strong></td>" +
"<td><input type='file' id='flImage' name='flImage[]' multiple /></td></tr></table>");
Now i want to store the image uploaded above in variable 'flImage', in a variable 'user' like other inputs value from textbox and labels value are stored through jquery in var 'user' as given below
<script type="text/javascript">
$(function () {
$(document).on("click", "[id*=btnFrmSubmit]", function () {
var user = {};
user.PRODUCT_ID = 1;
user.REVISION = $("#Revision").text();
user.P_GROUP = $("[id*=P_Group]").val();
user.IMG1 = $("#flImage")[0].files;
$.ajax({
type: "POST",
url: "TDC.aspx/SaveFrmDetails",
data: '{user: ' + JSON.stringify(user) + '}',
//data: JSON.stringify({user:user}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert("User has been added successfully.");
window.location.reload();
}
});
return false;
});
});
</script>
But while stringifying the data in json it results in error. So any idea how to stringify image in json will be appreciated.