以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]Ajax传递的数组使用问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=165339) |
-- 作者:fczhaobo -- 发布时间:2021/5/14 11:24:00 -- [求助]Ajax传递的数组使用问题 将B网页传递过来的数组:[ "yfsh0229", "654321" ] ,供A网页使用,不成功,请帮忙看一下,谢谢! B网页代码: Dim ja As New Jarray \'定义数组 ja.Add(zhanghao) ja.Add(mima) e.WriteString(ja.ToString) 传递的例子是:"[ "yfsh0229", "654321" ] " js代码: function getUserxx() { var mycars = new Array() mycars = sendAjaxText("","logon_wx.htm","",false); // [ "yfsh0229", "654321" ] //alert(mycars) document.getElementById("userzhanghao").valueL=mycars[0]; document.getElementById("password").value=mycars[1];
} A网页代码: Dim e As RequestEventArgs = args(0) Dim wb As new weui wb.AppendHTML("<style>#btn2:before {position: relative;right: 5px; top: 5px;content: url(./images/weixin24.png);}</style>",True) wb.AppendHTML("<style>#btn1:before {position: relative;right: 5px; top: 5px;content: url(./images/mima24.png);}</style>",True) wb.InsertHTML("<div style=\'width:100%;text-align:center;\'><img style=\'width:35%;height:auto;\' src=\'.\\logo.png\'></div>") wb.AddPageTitle("","pageheader","逸飞书画云ERP管理系统","") If e.PostValues.ContainsKey("Userzhanghao") AndAlso e.PostValues.ContainsKey("password") Then \'判断是否是验证失败后的重新登录 \'Or e.GetValues.ContainsKey("openid") wb.AddTopTips("","toptip1","用户名或密码错误!").msec = 2000 \'如果用户通过登录按钮访问,则给用户一个2秒的提示. End If wb.AddForm("","form1","logon.htm") With wb.AddInputGroup("form1","ipg1") With .AddInput("userzhanghao","ERP账号","text") .PlaceHolder= "请输入ERP账号" \'.Readonly = False \'输入框是否只读 .Value = e.Cookies("userzhanghao") End With With .AddInputCell("ic2") .AddLabel("lyz","密 码",0) .AddInput("password","password",1).PlaceHolder= "ERP密码" .AddVcodeButton("vyz","忘记密码",2).Attribute="" End With End With With wb.AddButtonGroup("form1","btg1",False) .Add("btn1", "密码登录", "submit").Kind = 1 With .add("btn2","微信一键登陆","") .Kind = 1 .Attribute="" End With End With wb.AppendHTML("<script src=\'./lib/table.js\'></script>") \'引入脚本文件 wb.AppendHTML("<script>" & vars("js-logon-wx") & "</script>") \'引入脚本文件 e.WriteString(wb.Build) \'生成网页 [此贴子已经被作者于2021/5/14 11:26:40编辑过]
|
-- 作者:fczhaobo -- 发布时间:2021/5/14 11:40:00 -- 现在的主要问题是:JS中,数组的问题,解析不出来。 js代码: function getUserxx() { var mycars = new Array() mycars = sendAjaxText("","logon_wx.htm","",false); // [ "yfsh0229", "654321" ] //alert(mycars) document.getElementById("userzhanghao").valueL=mycars[0]; document.getElementById("password").value=mycars[1]; document.getElementById("p1").innerHTML=mycars; //这个显示就没有问题
} [此贴子已经被作者于2021/5/14 11:41:14编辑过]
|
-- 作者:有点蓝 -- 发布时间:2021/5/14 11:47:00 -- function getUserxx() { var mycars = sendAjaxText("","logon_wx.htm","",false); // [ "yfsh0229", "654321" ] //alert(mycars) var ob = JSON. parse(mycars); document.getElementById("userzhanghao").valueL=ob[0]; document.getElementById("password").value=ob[1]; document.getElementById("p1").innerHTML=mycars; //这个显示就没有问题
}
|
-- 作者:fczhaobo -- 发布时间:2021/5/14 11:55:00 -- 成功,太感谢了,看来JS基础太差了! |
-- 作者:fczhaobo -- 发布时间:2021/5/14 14:52:00 -- Dim jo As New JObject jo("zhanghao") = zhanghao jo("mima") = mima e.WriteString(jo.ToString) Return Nothing 延申一下,如果生成的是json对像,在JS里如何解析,谢谢! function getUserxx() { var mycars = sendAjaxText("","logon_wx.htm","",false); // { "zhanghao":"yfsh0229", "mima":"654321" } alert(mycars) var ob = JSON.parse(mycars); //转换成JSON对像 document.getElementById("userzhanghao").value=ob("zhanghao").ToString(); document.getElementById("password").value=ob("mima").ToString(); }
|
-- 作者:有点蓝 -- 发布时间:2021/5/14 14:55:00 -- document.getElementById("userzhanghao").value=ob.zhanghao; |