为什么一直报 res_url未定义?
发布于 5 年前 作者 jiaxiulan 8157 次浏览 来自 问答

????

我有定义的      ?????

8 回复

能帮我看一下吗?我不太懂json的说

嗯嗯,好的

嗯嗯,好的,谢谢

我去掉的话

// pages/release/release.js

var app = getApp();

Page({

  /**

   * 页面的初始数据

   */

  data: {

    src: “”,

    imageList: [],

    countIndex: 3,//最多上传图片的数量

    count: [1, 2, 3, 4, 5, 6, 7, 8, 9],

    tip:’’,

    user: ‘’,

    p: ‘’,

    title: ‘’,

    content: ‘’,

 

  },

  //获取多张图片

  chooseImage: function () {

    var that = this;

    wx.chooseImage({

      count: this.data.count[this.data.countIndex],

      success: function (res) {

        console.log(res)

        that.setData({

          imageList: res.tempFilePaths

        })

      }

    })

  },

  previewImage: function (e) {

    var current = e.target.dataset.src

    wx.previewImage({

      current: current,

      urls: this.data.imageList

    })

  },

  //获取视频

  video:function(){

    var that = this;

    wx.chooseVideo({

      success:function(res){

        that.setData({

          src: res.tempFilePath,

        })

 

      }

    })

  },

  //获取输入框内容

  formBindsubmit:function(e){

    if (e.detail.value.user.length == 0) {

      this.setData({

        tip: ‘提示:用户名和密码不能为空!’,

        user: ‘’,

 

      })

    } else {

      this.setData({

        tip: ‘’,

        user: ‘用户名:’ + e.detail.value.user,

      })

    }

  },

  //录音

  startRecode: function () {

    var that = this;

    console.log(“start”);

    wx.startRecord({

      success: function (res) {

        console.log(res);

        var tempFilePath = res.tempFilePath;

        that.setData({ recodePath: tempFilePath, isRecode: true });

      },

      fail: function (res) {

        console.log(“fail”);

        console.log(res);

        //录音失败

      }

    });

  },

  //结束录音 

  endRecode: function () {

    var that = this;

    console.log(“end”);

    wx.stopRecord();

    that.setData({ isRecode: false });

    wx.showToast();

    setTimeout(function () {

      var urls = app.globalData.res_url;

      console.log(that.data.recodePath);

      wx.uploadFile({

        url: urls,

        filePath: that.data.recodePath,

        name: ‘file’,

        header: {

          ‘content-type’: ‘multipart/form-data’

        },

        success: function (res) {

          var str = res.data;

          var data = JSON.parse(str);

          if (data.states == 1) {

            var cEditData = that.data.editData;

            cEditData.recodeIdentity = data.identitys;

            that.setData({ editData: cEditData });

          }

          else {

            wx.showModal({

              title: ‘提示’,

              content: data.message,

              showCancel: false,

              success: function (res) {

              }

            });

          }

          wx.hideToast();

        },

        fail: function (res) {

          console.log(res);

          wx.showModal({

            title: ‘提示’,

            content: “网络请求失败,请确保网络是否正常”,

            showCancel: false,

            success: function (res) {

            }

          });

          wx.hideToast();

        }

      });

    }, 1000)

  },

  /**

   * 生命周期函数–监听页面加载

   */

  onLoad: function (options) {

    //接口调用示例

    var that = this

    //获取请求地址的url

    var res_url = app.globalData.res_url;

 

    //发起请求

    wx.request({

      //接口地址

      url: res_url + ‘index.php?g=admin&m=wxxcx&a=release’,

      method: ‘GET’,

      //请求数据

      data: {

        id: ‘1’,

        name: ‘ceshi’,

 

      },

      header: {

        ‘content-type’: ‘application/json’

      },

      //成功后回调

      success: function (res) {

        console.log(res.data)

        that.setData({

          result: res.data

        })

      }

    })

  },

  navbarTap: function (e) {

    this.setData({

      currentTab: e.currentTarget.dataset.idx

    })

  }

 

})

这是js里的代码,有点多。。。。   显示录音结束里的       var data = JSON.parse(str);      出问题了?????

JSON.parse是将字符串转换成json类型的数据的,看看你里面是不是已经是json数据了

看不到你全部的代码。不知道具体哪里错了,你可以点击一下at success 后面扩号里面的地址,会跳转到你又问题的地方。

不要var aaa = bbb =1,这种语法错误的。

回到顶部