小程序学习记录:读取discuz生成的json数据

 

在discuz后台数据库中建表,testjson,并输入两条记录:

testjson.php:

<?php

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

header("Content-Type:text/html;charset=GB2312");

require_once libfile('function/discuzcode');

$query = DB::query('SELECT * FROM TESTJSON'); 
while($data = DB::fetch($query)){
	$list[] = array(	
		'id' => urlencode($data['Id']),
		'txt' => urlencode($data['txt'])
	);
}
echo urldecode(json_encode($list));

?>

修改小程序自动生成的模板文件index.js文件中的bindViewTap事件,原来单击头像显示操作日志,变成console显示json内容:

  bindViewTap: function() {
    // wx.navigateTo({
    //   url: '../logs/logs'
    // })

    wx.request({
      method: "GET",
      url: 'http://www.XXXXX.com/test_ent.php',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
        console.log(res)
      }
    })

  },

设置一下项目域名不限制:详情——复选“不校验合法域名...”

单击头像,console显示结果:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章