赞
踩
通过ajax向控制器传值并接收返回值于data中,且返回数据需在前端输入框中显示
- [AllowAnonymous]
- public JsonResult getCardReader()
- {
- //StreamReader reader = new StreamReader(Path, System.Text.Encoding.GetEncoding("UTF-8"));
- //启动卡号读卡器ReadCardState 0禁用1检测2完成
- List<CRKCommunication> CRKCom = CRKCommunicationservice.GetModels(p => true).ToList();
- //if (CRKCom.Count > 0)
- //{
- // CRKCom[0].ReadCardState = 1;
- // CRKCommunicationservice.Update(CRKCom[0]);
- //}
- CRKCom[0].ReadCardState = 1;
- CRKCommunicationservice.Update(CRKCom[0]);
-
- //文件路径 取字符串
- string Path = @"C:\Users\Administrator\Desktop\kh.txt";
- string kno = System.IO.File.ReadAllText(Path, System.Text.Encoding.Default);
-
- string SmartCardNumber = "";
- string Number = "41018105" + kno + DateTime.Now.ToString("yyyyMMdd");
- //智慧卡号列表(数据库中与当前时间卡号相同,且卡号状态不为为使用中 的数据)
- List<card_info> cardList = card_infoservice.GetModels(p => true).Where<card_info>(p => p.Card_State != "1" && p.BusinessNumber.Substring(0, Number.Length) == Number).ToList();
- SmartCardNumber = Number + (cardList.Count + 1).ToString("000");
-
-
- var res = new JsonResult();
- res.Data = "{\"kno\"" + ":" + kno + ",\"SmartCardNumber\"" + ":" + "\"" + SmartCardNumber + "\"" + "}";
- return res;
- }
- <html>
- <head>
- <script>
- form.on("submit(CardReader)", function (data) {
- //layer.msg(JSON.stringify(data.field));
- laycy.ajax({
- url: '/StockOI/getCardReader',
- type: 'post',
- data: data.field,
- dataType: "json",
- success: function (da) {
- var obj = JSON.parse(da)//将字符串转换为json对象
- form.val("rmdj", {
- //"输入框Name": json键值
- "card0": obj.kno
- , "SmartCardNumber": obj.SmartCardNumber
- });
- },
- error: function (e) {
- layer.alert("保存失败!请确认参数填写是否正确!");
- }
- });
- return false;
- });
- <script></script>
- </head>
- <body></body>
- </html>
JsonResult返回json格式的字符串,前端ajax接收后解析为json对象并对输入框进行赋值
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。