I am able to get the element to Code-Behind by Using the Ajax-Call But I am unable to Deserialize the element in Code-Behind in asp.net
This is my Ajax call
function responseData2() {
var demodata = [];
var oListbox = $("#submitlistbox2").each(function () {
var data = $(this).text() + " " + $(this).val() + "\n";
alert("The Names are: " + data);
demodata.push({
var_name_data: data,
});
});
$.ajax({
url: "url",
type: "POST",
contentType: "application/json; charset=utf-8",
cache: false,
data: "{ 'selectedJobSheet': '" + demodata + "'}",
success: function (data) {
data = $.parseJSON(data.d);
alert(data);
alert("success");
},
error: function (response) {
alert(response);
alert("error");
}
});
}
My Code-Behind: How to retrive the element In Code behind:My ajax call returning data in Single string value "[object Object]"
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static object Details4(string selectedJobSheet)
{
try
{
string constr = ConfigurationManager.ConnectionStrings["Constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("select customer_id,first_name from jobsheetDetails", con))
{
string _data = "";
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
_data = JsonConvert.SerializeObject(ds.Tables[0]);
}
return _data;
}
}
}
catch (Exception)
{
throw;
}
}
How to deserialize the element and how bind the element to list or array