jquery - Extract data from Json return object -
in controller calling webservice
metadata.client.service.client returnclient = new metadata.client.service.client(); returnclient = client.updateclient(updateclient); homecoming json(new { returnclient }, jsonrequestbehavior.allowget);
in .cshtml ajax phone call below
$.ajax( { type: "get", contenttype: "application/json; charset=utf-8", url: '@url.action("updaterecord", "client")', data: { "id": id, "name": clientname, "code": clientcode, "typeid": clienttypeid, "clientstatuscode": clientstatuscode }, datatype: "json", beforesend: function () {//alert(id); }, error: function (request) { alert('error'); alert(request.responsetext); }, success: function (data) { alert('success'); console.log(data); //var parsed = json.parse(data); //alert(parsed); //var k = json.stringify(data); //alert(parsed); }
i tried several ways extract data. in console.log
showing below
[09:27:07.989] ({returnclient:{extensiondata:{}, clientcode:"c09091", clientid:39, clientname:"test1", clientstatus:[{extensiondata:{}, statuscode:{extensiondata:{}, name:"active", statuscodeid:5}, statustype:{extensiondata:{}, name:"oe", statustypeid:1}}], clienttype:{extensiondata:{}, clienttypeid:7, clienttypename:"fdfd"}}})
please can help out extract info
ie, clientname, clientcode, clientid, clientstatus.statuscode, clientstatus.name, clientstatus.statuscodeid, statustype.name
success: function (data) { var ccode = data.returnclient.clientcode; var cid = data.returnclient.clientid; var cname = data.returnclient.clientname; var ctypeid = data.returnclient.clienttype.clienttypeid; var ctypename = data.returnclient.clienttype.clienttypename; (var = 0; < data.returnclient.clientstatus.length; i++) { var codename = data.returnclient.clientstatus[i].statuscode.name; var codeid = data.returnclient.clientstatus[i].statuscode.statuscodeid; var typename = data.returnclient.clientstatus[i].statustype.name; var typeid = data.returnclient.clientstatus[i].statustype.statustypeid; } }
jquery asp.net-mvc-4
No comments:
Post a Comment