I am trying to send a list of ids to a generic handler which will process these ids and do further logic. I am sending the list of ids such as items: ["32", "33"]
. I am not able to get the ids of these items. I've tried to serialize, deserialize, and place the values in an object without any luck. Could you help me see where I am going wrong in this process?
============JavaScript ==============
$.ajax({
type: "post",
data: JSON.stringify({ 'items': itemIds }),
url: 'deleteItems.ashx',
success: function (data) {
console.log('working');
console.log(data);
},
error: function (request, err) {
console.log(err);
}
});
============= DATA RETURNED FROM delteItems.ashx in console.log =============
"items": [
"39"
]{"items":["39"]}
============ DeleteItems.ashx =================
//not sure if this is needed
public class inventoryItems
{
public List<string> items { get; set; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string json = new StreamReader(context.Request.InputStream).ReadToEnd();
//iif I use a list in DeserializeObject with the inventoryItems class, I return an error in my ajax file.
dynamic inventoryItems = JsonConvert.DeserializeObject(json);
foreach (var obj in inventoryItems)
{
context.Response.Write(obj);
// return each id and do more logic
}
- DeleteItems.ashx is returning data as "text/plain"