小程序學習記錄:讀取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顯示結果:

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