FIsh. 2019-04-21 20:59 采纳率: 0%
浏览 700

小程序连接数据库,返回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条回答 默认 最新

  • 代码的灵魂是bug! 2019-04-22 14:03
    关注

    你的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.....");
      }
    })
    },
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图