My application contains multiple <input type="file"> fields and I need to save the file paths. I am converting the paths into a JSON string and sending the result to a ColdFusion CFC method. On the ColdFusion side I am deserializing the JSON string using DeserializeJSON(), but am getting an error:
JSON Parsing ending with unexpected character
.
I had the same issue when passing a serialized FORM structure into a ColdFusion page. I fixed it by URL encoding the value with URLEncodedFormat(). Would url encoding the above JSON string fix this issue or is my code for passing the file paths as a JSON string incorrect?
My client side code is below:
var lttr_docs = {};
for(i=1;i<length;i++)
{
lttr_docs['file_id_'+i] = $('#file_id_'+i).val();
}
$.ajax({
url: "xyz/component.cfc?method=methodName",
type: "GET",
dataType:"json",
data: JSON.stingify(lttr_docs),
success: function(res) {
},
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
});
Basically the problem is while desrializing the JSON string in server side. Can I do some thing on client side to fix this or do I need to completely rely on a server side fix?