knock.js的subscribe使用 通过$.ajax(); $get();解析JSON数据
来源:互联网 发布:js null undefined 编辑:程序博客网 时间:2024/06/06 04:01
//CS代码
<pre class="csharp" name="code">public ActionResult GetPhysicalSKUCost(int RequestTypeID, int SystemTypeID, int PhySKUID) { string serviceAddress = ConfigurationManager.AppSettings["MyCapacityService"].ToString(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress + "/json/GetPhysicalSKUCost?RequestTypeID=" + RequestTypeID + "&SystemTypeID=" + SystemTypeID + "&PhySKUID=" + PhySKUID); string result = string.Empty; StreamReader responseStream = null; HttpWebResponse webresponse = null; try { webresponse = (HttpWebResponse)request.GetResponse(); } catch (WebException ex) { webresponse = (HttpWebResponse)ex.Response; } Encoding enc = System.Text.Encoding.GetEncoding("utf-8"); responseStream = new StreamReader(webresponse.GetResponseStream(), enc); result = responseStream.ReadToEnd(); responseStream.Close(); webresponse.Close(); return Json(new { success = true, data = result }, JsonRequestBehavior.AllowGet); }
//返回的JSON数据
{"Root":{"IsAddable":"0","DomainEntity":{"ID":"11000189","Name":"PHY - Standard","DynamicAttributeName":"Custom Column (Effective FY)","DynamicAttributeValue":"256.99","Code":"PSKU000008","TypeFlag":"ECS only","GroupID":"2030","UpdateBy":"REDMOND\\v-brenpe","UpdateDt":"10/01/2014","IsExtensible":"true"}}}
</pre><pre class="javascript" name="code">//JS代码
self.selPhySKU.subscribe(function (newValue) { self.BindStorage( self.selRequestType() ? self.selRequestType().Code() : "", self.selServRole() ? self.selServRole().ID() : 0, self.SKUID(), self.selClusterType() ? self.selClusterType().ID() : 0, self.selSystemType() ? self.selSystemType().ID() : 0, self.selDatacenter() ? self.selDatacenter().ID() : 0, self.requestID() ? self.requestID() : 0 ); self.ResetSQLVersion(); if (newValue && newValue.ID() != 10150 && self.isLoading == false && self.CurrentPage == "admin") { self.BindDefaultSKUOrdered(newValue.ID()); } self.GetStorageLimit(self.selDatacenter() ? self.selDatacenter().ID() : 0, self.selVBOSlocation() ? self.selVBOSlocation().ID() : 0, newValue ? newValue.ID() : 0); //add by penglu on 20151214 for bug 15725 //RequestType="Physical";SystemType="SystemType" if (self.selRequestType() != null && self.selRequestType().ID() == 390 && self.selSystemType() != null && self.selSystemType().ID() == 700 && self.selPhySKU() != null) { //method 1 if (newValue.ID() == 10150) { //PHY Non-standard/Other if ($("#divPhysicalSKUCost").length > 0) { //Clear divSKUCost Content //$("#divPhysicalSKUCost").empty(); $("#divPhysicalSKUCost").remove(); } //Right below the SKU dropdown Display the price 0 for the selected "PHY Non-standard/Other" $("#Dep_Mes_Physical").after("<div class='k-icon k-warning' id='divPhysicalSKUCost'>The selected SKU will cost $ 0<br /></div>"); } else { ////method 1 //$.ajax({ // type: "GET", // url: "/Order/order/GetPhysicalSKUCost", // data: { "RequestTypeID": self.selRequestType().ID(), "SystemTypeID": self.selSystemType().ID(), "PhySKUID": self.selPhySKU().ID() }, // dataType: "json", // success: function (item) { // var varJson = JSON.parse(item.data); // var varPhysicalSKUCost = (varJson != null && varJson.Root.DomainEntity != null) ? varJson.Root.DomainEntity.DynamicAttributeValue : 0; // if ($("#divPhysicalSKUCost").length > 0) { //Clear divSKUCost Content // //$("#divPhysicalSKUCost").empty(); // $("#divPhysicalSKUCost").remove(); // } // //Right below the SKU dropdown Display the price for the selected SKU // $("#Dep_Mes_Physical").after("<div class='k-icon k-warning' id='divPhysicalSKUCost'>The selected SKU will cost $ " + varPhysicalSKUCost + "<br /></div>"); // //Add a pop up dialog after selecting a SKU that shows "The selected SKU will cost $ XX.XX" WITH an OK Button // var popupHtml = "<div id='req-edit-Popup' class='font-S-13'>" // + "<div class='p-bottom-20'>The selected SKU will cost $ " + varPhysicalSKUCost + "<br /></div>" // + "<div><a class='btn-yes popup-close'>OK</a></div>"; // McUtility.showNoClosePopUpPage(popupHtml, 400); // } //}); //method 2 $.get("/Order/order/GetPhysicalSKUCost", { "RequestTypeID": self.selRequestType().ID(), "SystemTypeID": self.selSystemType().ID(), "PhySKUID": self.selPhySKU().ID() }, function (item) { var varJson = JSON.parse(item.data); var varPhysicalSKUCost = (varJson != null && varJson.Root.DomainEntity != null) ? varJson.Root.DomainEntity.DynamicAttributeValue : 0; if ($("#divPhysicalSKUCost").length > 0) { //Clear divSKUCost Content //$("#divPhysicalSKUCost").empty(); $("#divPhysicalSKUCost").remove(); } //Right below the SKU dropdown Display the price for the selected SKU $("#Dep_Mes_Physical").after("<div class='k-icon k-warning' id='divPhysicalSKUCost'>The selected SKU will cost $ " + varPhysicalSKUCost + "<br /></div>"); //Add a pop up dialog after selecting a SKU that shows "The selected SKU will cost $ XX.XX" WITH an OK Button var popupHtml = "<div id='req-edit-Popup' class='font-S-13'>" + "<div class='p-bottom-20'>The selected SKU will cost $ " + varPhysicalSKUCost + "<br /></div>" + "<div><a class='btn-yes popup-close'>OK</a></div>"; McUtility.showNoClosePopUpPage(popupHtml, 400); }, "json"); } } //add by penglu on 20151214 for bug 15725 });
0 0
- knock.js的subscribe使用 通过$.ajax(); $get();解析JSON数据
- jquery eval()解析JSON,ajax通过return返回数据,js读取解析JSON数据
- Ajax -- $.get() 方法解析 JSON 数据
- 用原生js,json解析ajax传回来的数据
- ajax接收json数据到js解析
- 使用js解析json数据
- asp.net 使用ajax请求地址接口数据 ajax返回类型是json js get post请求数据
- ajax 提交post get 数据,得到json结果解析
- 使用QJson解析Qt通过UDP发送的JSON数据
- jquery通过ajax方式获取json数据和解析
- ajax解析JSON数据
- 【Chart.js】通过Ajax请求JSON数据来绘制图表
- Ajax解析返回的Json数据
- ajax中解析json数据的方式
- ajax解析Json数据的方法
- .js循环读写通过ajax发送并返回的json数据
- js使用eval解析json数据
- JavaWeb将数据包装成JSON以及JSP通过ajax对JSON的获取与解析(代码实例)
- 微信企业号开发四:文件上传到微信服务器
- jquery 跳出each循环
- 一个有关Golang变量作用域的坑
- Linux的bg和fg命令简单介绍
- 多类的设计
- knock.js的subscribe使用 通过$.ajax(); $get();解析JSON数据
- [时空与飞翔]2015.12.16日 天窗打开 时空之门打开
- 数据结构和算法经典100题-第21题
- Oracle中查看所有表和字段
- Linux进程间通信——使用共享内存
- mysql 重置主键
- iOS 自动布局 同一行的几个控件 需要其中某几个不被压缩,其中某几个不被拉伸
- memdup_user()函数
- 23种设计模式C++实例之装饰模式