c# - Ajax method not executes -


this question has answer here:

enter image description here ajax method not calling webmethod , not update data database. try without , json.strigify not work properly. using gridview in o have take textboxes , performing update task on it.
my javascript code -

$("body").on("click", "[id*=gridview1] .update", function () {                     var row = $(this).closest("tr");                     $("td", row).each(function () {                         if ($(this).find("input").length > 0) {                             var span = $(this).find("span");                             var input = $(this).find("input");                             span.html(input.val());                             span.show();                             input.hide();                         }                     });                     row.find(".edit").show();                     row.find(".delete").show();                     row.find(".cancel").hide();                     $(this).hide();                     var id = row.find(".id").find("span").html();                     var ledger = row.find(".ledger").find("span").html();                     var datafld = row.find(".datafld").find("span").html();                     var adatafldm = row.find(".adatafld").find("span").html();                     var ltype = row.find(".ltype").find("span").html();                     var ctype = row.find(".ctype").find("span").html();                     var lacno = row.find(".lacno").find("span").html();                     var type = row.find(".type").find("span").html();                     var link = row.find(".link").find("span").html();                     var tper = row.find(".tper").find("span").html();                     var tcalc = row.find(".tcalc").find("span").html();                      $.ajax({                         type: "post",                         contenttype: "application/json; charset=utf-8",                         url: "daybookmast.aspx/updatecustomer121",                         data:json.stringify('{id: ' + id + ',ledger: ' + ledger + ', datafld: "' + datafld + '", adatafldm: "'                             + adatafldm + '", ltype: "' + ltype + '", ctype: "' + ctype + '", lacno: "'                             + lacno + '", type: "' + type + '", link: "' + link + '", tper: "'                             + tper + '", tcalc: "' + tcalc + '" }'),                         datatype: "json",                                             success: function () {                             if (confirm("are sure want change !") == true) {                                 alert("data updated successfully");                             } else {                                 alert("you have canceled changes");                             }                          },                         error: function () {                             alert("error while updating data of :" );                         }                      });                      return false;                 }); 

my c# code is-

    [webmethod]     public static void updatecustomer121(int id,string daycode, string ledger, string datafld, string adatafldm, string ltype, string ctype, string lacno, string type, string link, string tper, string tcalc)     {        using (sqlconnection con = new sqlconnection(strconnection))         {             using (sqlcommand cmd = new sqlcommand("update daybookdetails set daycode=@daycode,ledger = @ledger,datafld = @datafld,adatafld = @adatafld,ltype = @ltype,ctype = @ctype,lacno = @lacno,type = @type,link = @link,tper = @tper,tcalc = @tcalc  id = @id"))             {                 cmd.parameters.addwithvalue("@id",id);                 cmd.parameters.addwithvalue("@daycode", daycode);                 cmd.parameters.addwithvalue("@ledger", ledger);                 cmd.parameters.addwithvalue("@datafld", datafld);                 cmd.parameters.addwithvalue("@adatafld", adatafldm);                 cmd.parameters.addwithvalue("@ltype", ltype);                 cmd.parameters.addwithvalue("@ctype", ctype);                 cmd.parameters.addwithvalue("@lacno", lacno);                 cmd.parameters.addwithvalue("@type", type);                 cmd.parameters.addwithvalue("@link", link);                 cmd.parameters.addwithvalue("@tper", tper);                 cmd.parameters.addwithvalue("@tcalc", tcalc);                 cmd.connection = con;                 con.open();                 cmd.executenonquery();                 con.close();             }         }     } 

you don't have daycode in javascript, expect in c# web method

{id: ' + id + ',ledger: ' + ledger + ', datafld: "' + datafld + '", adatafldm: "

vs

int id,string daycode, string ledger, string datafld, string adatafldm,

share|improve answer
    
now remove sql query , webmethod doesn't work. web method not calling give breakpoint – chetan sarode sep 22 '16 @ 12:12
    
take string json.stringif("...") normal string in javascript , on if have null or undefined or that. had once similar excemtion (code ajax don't go web method") , parsing problem (in javascript put string, , web method expected double). – zchpit sep 22 '16 @ 12:15
    
how apply it.. – chetan sarode sep 22 '16 @ 12:26
    
var jsonstr = '{id: ' + id + ',ledger: ' + ledger + ', datafld: "' + datafld + '", adatafldm: "' + adatafldm + '", ltype: "' + ltype + '", ctype: "' + ctype + '", lacno: "' + lacno + '", type: "' + type + '", link: "' + link + '", tper: "' + tper + '", tcalc: "' + tcalc + '" }' – zchpit sep 22 '16 @ 12:31

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -