1、客户端关键代码
页面布局代码(index.wxml)
<input placeholder="请输入您的用户名" bindinput="getUserName"/>
<input password="{{password}}" placeholder="请输入您的密码" bindinput="getPassword"/>
<button bindtap="login">登录</button>
<view bindtap="showPassword">显示密码</view>
页面逻辑代码(index.js)
var OBJ_PAGE_DATA={};
OBJ_PAGE_DATA.data={
password:true
}
var STR_USERNAME='';
var STR_PASSWORD='';
OBJ_PAGE_DATA['getUserName']=function(params){
STR_USERNAME=params.detail.value;
}
OBJ_PAGE_DATA['getPassword']=function(params){
STR_PASSWORD=params.detail.value;
}
OBJ_PAGE_DATA['login']=function(){
wx.request({
url: '',//使用https开头的服务器地址
data: {
username:STR_USERNAME,
password:STR_PASSWORD
},
method: 'GET',
success: function(callback){
console.log(callback)
var str_serverRetureData=callback.data;
if(str_serverRetureData=="request success"){
wx.showToast({
title:"请求成功"
})
}else{
wx.showModal({
title:"错误",
content:"请求失败",
showCancel:false
})
}
}
})
}
OBJ_PAGE_DATA['showPassword']=function(){
var obj_setData={
password:false
}
this.setData(obj_setData);
}
Page(OBJ_PAGE_DATA)
2、服务器端代码(PHP)
<?php if($_REQUEST["username"]=="wxapp" && $_REQUEST["password"]=="titf" ){ echo "request success"; }else{ echo "request failed"; } ?>