|
发表于 2017-6-27 13:57:16
|
显示全部楼层
发布个webservice,然后用ajax post,返回后赋值控件,我最近也做了个类似项目,wex5+.net+微信企业号,贴部分代码给你参考下
带一个方法的完整js文件:
define(
function(require){
var $= require('jquery'),
justep = require('$UI/system/lib/justep');
var user=new Member();
var ws="http://195.168.50.121:8001/ws.asmx/"; //ws地址
function Member()
{
this.UserAccount="";
this.UserDisplayName="";
this.Department="";
}
//获取用户信息
GetMember:function(uid,ps)
{
var data = JSON.stringify({"account":uid,"password":ps});
$.ajax({
url: ws+"GetMember",
type: "POST",
dataType: "json",
async: false,
global: false,
contentType: "Application/Json",
data: data,
success: function (json) {
if(json.d.length>0)
{
var js=JSON.parse(json.d);
user.UserAccount=js.UserAccount;
user.UserDisplayName=js.UserDisplayName;
user.Department=js.Department;
}
else
{
throw justep.Error.create("获取用户信息失败!");
}
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
throw justep.Error.create("获取用户信息失败!请检查网络或联系系统管理员");
}
});
return user;
}
};
});
调用如下:
var BPM=require("../MyJS/BPMJS"); //加载js文件
var user=BPM.user;
user= BPM.GetMember(window.uid,window.ps);
this.comp('UserDisplayName').val(user.UserDisplayName);
this.comp('Department').val(user.Department);
this.comp('appdate').val(justep.Date.toString(new Date(),'yyyy-MM-dd hh:mm:ss'));
另外:webservice return 的数据格式需要是json格式 |
|