I have this code, and when i'm executing it this keeps showing the same error: Invalid JSON primitive: titles.
Client Side:
var title = new Array();
...
for (var i = 0; i < names.length; ++i) {
title[i] = '{ "titulo' + i + ':"' + names[i] + '"}';
}
$("#gif").show();
$.ajax({
async: true,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
type: "POST",
data: { titles: title },
url: "../handlers/saveUpload.ashx",
success: function (msg) {
$("#gif").hide();
}
});
Server Side:
context.Response.ContentType = "application/json";
var data = context.Request;
var sr = new StreamReader(data.InputStream);
var stream = sr.ReadToEnd();
var javaScriptSerializer = new JavaScriptSerializer();
var arrayOfStrings = javaScriptSerializer.Deserialize<string[]>(stream);
foreach (var item in arrayOfStrings)
{
context.Response.Write(item);
}
Regards