小程序连接数据库,返回undefined错误 数据上传不了
  1. 在小程序做登录注册功能,但注册这块,小程序一直返回undefined,后台数据也没有显示成功!

2.myeclisep和数据库sql 都没有问题。怀疑是小程序这边的问题,为什么上传不了数据

  1. 这是JS文件

var app = getApp();
Page({
data: {
username: null,
password: null,
jieguo: null
},
dian: function (e) {
var that = this;
that.username = e.detail.value.name;
that.password = e.detail.value.password;
console.log(that.username);
wx.request({
url: 'http://localhost:8080/mini',
data: {
name: that.username,
password: that.password
},

  header: {
    'content-type': 'application/json' // 默认值
  },
  success: function (res) {
    console.log(res.data[0]);
    console.log(res.data[0].jieguo);
    that.jieguo = res.data[0].jieguo;
    if (that.jieguo == 1) { wx.redirectTo({ url: "../login/login" }) }
  },
  fail: function (res) {
    console.log(".....fail.....");
  }
})

},

usernameInput: function (event) {

console.log(event.detail.value);
this.setData({ username: event.detail.value })

},

passwordInput: function (event) {
this.setData({ password: event.detail.value })
}

})

5.

1个回答

你的dian这个方法中,代码错了,首先你已经定义了用户名和密码的获取方法,但在dian这个方法中没有正确使用,应该是这样:

dian: function (e) {
var that = this;
/*这个其实可以不要
that.username = e.detail.value.name;
that.password = e.detail.value.password;
console.log(that.username);
*/
wx.request({
url: 'http://localhost:8080/mini',
data: {
name: that.data.username,//这里获取的是data里面
password: that.data.password
},

  header: {
    'content-type': 'application/json' // 默认值
  },
  success: function (res) {
    console.log(res.data[0]);
    console.log(res.data[0].jieguo);
    that.jieguo = res.data[0].jieguo;
    if (that.jieguo == 1) { wx.redirectTo({ url: "../login/login" }) }
  },
  fail: function (res) {
    console.log(".....fail.....");
  }
})
},
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!