oninput(e){ var that=this that.data.identity=e.detail.value if(that.data.identity<18)return; wx.request({ url: app.globalData.api +'/Student_GetInfoByIdCard', data:{ token:app.globalData.token, identity:that.data.identity }, method: 'POST', header: { 'content-type': 'application/json' }, success(res){ var r = JSON.parse(res.data.d) // console.log(r.JsonStr.data1) var data=r.JsonStr.data1 console.log(data) if(that.data.identity.length===18){ that.setData({ nation: data.nation, //民族 teacherphone: data.teacherphone, //指导老师手机号 teacher: data.teacher,//指导老师 name: data.name,//姓名 phone: data.phone,//手机号 gender:data.gender,//性别 nationality:data.nationality,//国籍 birthday:data.birthday_shorter,//生日 pinyinlist:data.pinyin//拼音 }) } else { that.setData({ nation: '', //民族 teacherphone: '', //指导老师手机号 teacher: '',//指导老师 name: '',//姓名 phone: '',//手机号 gender:'', //性别 nationality:'', //国籍 birthday:'', //生日 pinyinlist:'' //拼音 }) } } }) },修改这段代码 身份证长度不满足18位不发送请求
时间: 2024-04-06 13:28:26 浏览: 111
node.js实现逐行读取文件内容的代码
修改后的代码:
oninput(e){
var that = this;
that.data.identity = e.detail.value;
if(that.data.identity.length < 18) {
that.setData({
nation: '',
teacherphone: '',
teacher: '',
name: '',
phone: '',
gender: '',
nationality: '',
birthday: '',
pinyinlist: ''
});
return;
}
wx.request({
url: app.globalData.api + '/Student_GetInfoByIdCard',
data: {
token: app.globalData.token,
identity: that.data.identity
},
method: 'POST',
header: {
'content-type': 'application/json'
},
success(res){
var r = JSON.parse(res.data.d);
var data = r.JsonStr.data1;
that.setData({
nation: data.nation,
teacherphone: data.teacherphone,
teacher: data.teacher,
name: data.name,
phone: data.phone,
gender: data.gender,
nationality: data.nationality,
birthday: data.birthday_shorter,
pinyinlist: data.pinyin
});
},
fail(err){
console.log(err);
}
});
}
修改内容:在判断身份证号长度时,使用字符串长度进行判断,如果长度小于18就清空显示的数据并返回。在发送请求时,将身份证号作为请求数据的一个参数传递。并且在请求成功后,将返回的数据更新到页面上。在请求失败时,打印出错误信息。
阅读全文