c# - How to remove current row from a html table in jQuery json? -
i want write code multipledelete
using jquery json.
this jquery code:
function deleteselected() { var categories = new array(); debugger; // iterate checkboxes , obtain checked values, unchecked values not pushed array $("input[type='checkbox']").each(function () //$('input[type=checkbox]').prop("checked", this.checked) { this.checked ? categories.push($(this).val()) : null; }); // assume urldata web method delete multiple records var urldata = "webform5.aspx/deleterecord"; debugger; $.ajax({ type: "post", contenttype: "application/json; charset=utf-8", url: urldata, data: "{ 'id':'"+json.stringify( categories)+"' }", // used convert array proper json format datatype: "json", success: function (dt) { // done whatever tasks if succeeded alert("entry deleted"); debugger; $("#example1").datatable(); //$("#example1").bind; debugger; }, error: function (result) { alert("error"); } }); }
this aspx code(codebehind multiple delete):
[webmethod] // note clear difference between single , multiple selections public static void deleterecord(list<int> id) { clscategorybl objproject = new clscategorybl(); // iterate through input list , pass process method (int = 0; < id.count; i++) { objproject.categorydelete(id[i]); } }
i want pass id aspx page problem output comes error popup.
error: function (result) { alert("error"); }
the below line return json array categories
"{ 'id':'"+json.stringify( categories)+"' }"
validate value http://jsonlint.com/ , check if result valid json.
since had declared method public static void deleterecord(list<int> id)
means expected input [1,2,3]
also use below line exact error coming
error: function (xhr, ajaxoptions, thrownerror) { alert("error # " + xhr + ajaxoptions + thrownerror); }
update 1:
below working code
var categories = new array(); // logic push categories.push(1); categories.push(2); categories.push(3); var valuetxt = "{ \"id\":\"" + json.stringify(categories) + "\" }"; var urldata = "webform1.aspx/deleterecord"; $.ajax({ type: "post", url: urldata, data: valuetxt, // used convert array proper json format contenttype: "application/json; charset=utf-8", datatype: "json", success: function (result) { // in result same data posted alert(result.d); }, error: function (xhr, ajaxoptions, thrownerror) { alert("error # " + xhr + ajaxoptions + thrownerror); } }); [webmethod] // change parameter string, convert json integer array public static string deleterecord(string id) { // - sample here returning same json of integer return id; }
Comments
Post a Comment