I am deleting item from cart through Jquery ajax,but it is not removing. It is returning "System.String[]".
  [WebMethod(EnableSession = true)]
  public string ClearItem(string Img)
    {
        try
        {
            if (Session["Items"] != null)
            {
                string[] session_item_arr = Session["Items"].ToString().Split('|');
                for (int i = 0; i < session_item_arr.Length; i++)
                {
                    string[] key_arr = session_item_arr[i].Split(',');
                    foreach (string item in key_arr)
                    {
                        if (item == Img)
                        {           
                            session_item_arr = session_item_arr.Where(val => val != session_item_arr[i]).ToArray();
                        }
                    }
                    bool item_inedx = Array.Exists(session_item_arr, x => x == session_item_arr[i]);
                    if (item_inedx)
                    {
                        Session["Items"] = session_item_arr[i];
                    }
                    else
                    {
                        Session["Items"] = session_item_arr;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return Session["Items"].ToString();
    }
Re: remove item from cart through jquery ajax 80 80

What is the value of Session["Items"]?

Re: remove item from cart through jquery ajax 80 80

It seems your array is empty, you are doing a check to see if it is not empty, try and check if it is empty i.e. alert("Oops, array is empty");

Then you know to go back to where you have created teh array, there might be a problem there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.