原创:微信小程序调用PHP后台接口,解析纯html文本
wx.request({
url: 'https://m.****.com/index.php/Home/Xiaoxxf/activity_detail?a_id='+options.id,//含富文本html
data: {
is_detail:1
},
method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: {
'Content-Type': 'application/json'
},
success: function (res) {
that.setData({
Article: res.data //一维数组json编码后对象
})
/**
* html解析
*/
var article = that.data.Article;
console.log("article = " + article);
WxParse.wxParse('article', 'html', article, that, 5);
console.log(res.data);
},
fail: function (res) { },
complete: function (res) { },
}),
其中,options.id是由前一个wxml页面动态传过来的参数。
github地址: https://github.com/icindy/wxParse,版本0.2
解决问题:微信小程序富文本html、md解析组件
1)复制wxParse文件夹到pages同目录
2)在wxml页面引入模板代码:
<import src="../../wxParse/wxParse.wxml"/>
<!--这里可以添加其他的任何wxml代码-->
富文本html框内容:<template is="wxParse" data="{{wxParseData:article.nodes}}"/>
// 引入wxParse.js解析文件
var WxParse = require('../../wxParse/wxParse.js');
page({...})
示例代码:
wx.request({
url: 'https://m.*****.com/index.php/Home/Xiaoxxf/activity_detail?a_id='+options.id,//含富文本html
data: {
is_detail:1
},
method: 'GET',
header: {
'Content-Type': 'application/json'
},
success: function (res) {
that.setData({
Article: res.data //一维数组json编码后对象,全部数据
})
/**
* html解析
*/
var article = that.data.Article;
console.log("article = " + article);
WxParse.wxParse('article', 'html', article, that, 5);
console.log(res.data);
},
fail: function (res) { },
complete: function (res) { },
})
public function activity_detail(){
$is_detail = I('is_detail');
if(!empty($is_detail)){ //富文本html文章
$a_id = I('a_id');
$a_id = intval($a_id)?$a_id:0;
if(empty($a_id)){
$data['code'] = 500;
$data['msg'] = '抱歉,文章已失效';
echo json_encode($data);
}else{
/* php方法:stripslashes() 将html文章去掉json转移字符\ --xzz0608*/
//获取结果为指定字段的二维数组,下面截取一维数组
$data =D()->query("select act_detail from xxf_witkey_activity where is_show = 1 and a_id = ".$a_id." order by a_id desc");
//var_dump($data);return ;
$data = $data[0];
$data = stripslashes(implode(',', $data));
$data = str_replace(array('src="/data/uploads/','src="data/uploads/'),array('src="http://www.xxiangfang.com/data/uploads/','src="http://www.xxiangfang.com/data/uploads/'),$data);
echo $data;
}
}else{ //普通字段(封面、特色、活动名称)
$a_id = intval(I('GET.a_id'));
$data =D()->query("select a_id,act_name,pic_url,introduction from xxf_witkey_activity where is_show = 1 and a_id = ".$a_id." order by a_id desc");
if($data)
$data = $data[0];
echo json_encode($data);
}
}
原创:微信小程序调用PHP后台接口,解析纯html文本的更多相关文章
- 原创:微信小程序开发要点总结
废话不多少,下面是对我从开发微信小程序的第一步开始到发布的总结,觉得对您有帮助的话,可以赞赏下,以对我表示鼓励. 一:首先注册登录微信公众平台,这个平台很重要,以后查文档全在上面看.https://m ...
- 微信小程序与Java后台通信
一.写在前面 最近接触了小程序的开发,后端选择Java,因为小程序的代码运行在腾讯的服务器上,而我们自己编写的Java代码运行在我们自己部署的服务器上,所以一开始不是很明白小程序如何与后台进行通信的, ...
- 微信小程序与Java后台的通信
一.写在前面 最近接触了小程序的开发,后端选择Java,因为小程序的代码运行在腾讯的服务器上,而我们自己编写的Java代码运行在我们自己部署的服务器上,所以一开始不是很明白小程序如何与后台进行通信的, ...
- 微信小程序的Web API接口设计及常见接口实现
微信小程序给我们提供了一个很好的开发平台,可以用于展现各种数据和实现丰富的功能,通过小程序的请求Web API 平台获取JSON数据后,可以在小程序界面上进行数据的动态展示.在数据的关键 一环中,我们 ...
- 微信小程序登录JAVA后台
代码地址如下:http://www.demodashi.com/demo/12736.html 登录流程时序登录流程时序 具体的登录说明查看 小程序官方API 项目的结构图: springboot项目 ...
- 微信小程序需要https后台的创业机会思考
最近比较关注微信小程序,而且微信小程序的后台必须强制要求https, https相对http成本要高很多了. 这里我感觉有2个商机 (1)提供https 中转服务器 ,按流量来收费 (2) 微信小程序 ...
- 图解微信小程序---调用API操作步骤
图解微信小程序---调用API操作步骤 什么是API API(Application Programming Interface,应用程序编程接口:是一些预先定义的函数,目的是提供应用程序与开发人员基 ...
- 小程序调用wx.chooseLocation接口的时候无法获取权限(ios)
ios手机小程序调用wx.chooseLocation接口的时候,获取权限的时候报authorize:fail:require permission desc这样子的错误,这是由于苹果的安全机制导致需 ...
- 记录一次用宝塔部署微信小程序Node.js后端接口代码的详细过程
一直忙着写毕设,上一次写博客还是元旦,大半年过去了.... 后面会不断分享各种新项目的源码与技术.欢迎关注一起学习哈! 记录一次部署微信小程序Node.js后端接口代码的详细过程,使用宝塔来部署. 我 ...
随机推荐
- Appium+python自动化6-Remote远程控制
前言 在第三篇启动app的时候有这样一行代码driver = webdriver.Remote('http://192.168.1.1:4723/wd/hub', desired_caps),很多小伙 ...
- coursera课程Text Retrieval and Search Engines之Week 4 Overview
Week 4 OverviewHelp Center Week 4 On this page: Instructional Activities Time Goals and Objectives K ...
- 网站流量分析指标-PV/UV/PR/IP
网站数据分析,经常会统计一个页面或者一个网站或者其他情况的PV/UV.下面简单说一下,这些量PV/UV/PR/IP. 1.PV PV(page view),即页面浏览量,或点击量.通常是衡量一个网络新 ...
- [leetcode]Sum Root to Leaf Numbers @ Python
原题地址:http://oj.leetcode.com/problems/sum-root-to-leaf-numbers/ 题意: Given a binary tree containing di ...
- 泛型 Generic 类型擦除引起的问题及解决方法
参考:http://blog.csdn.net/lonelyroamer/article/details/7868820#comments 因为种种原因,Java不能实现真正的泛型,只能使用类型擦除来 ...
- ButterKnife 注解 bindview
简介 官网:http://jakewharton.github.io/butterknife/ github:https://github.com/JakeWharton/butterknife 注意 ...
- SQL中以count或sum为条件的查询方式
在开发时,我们经常会遇到以“累计(count)”或是“累加(sum)”为条件的查询.比如user_num表: id user num 1 a 3 2 a 4 3 b 5 4 b 7 例1:查询出现 ...
- System.ComponentModel.Component : MarshalByRefObject, IComponent, IDisposable
#region 程序集 System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // C:\Windows\ ...
- ufldl学习笔记与编程作业:Softmax Regression(vectorization加速)
ufldl学习笔记与编程作业:Softmax Regression(vectorization加速) ufldl出了新教程,感觉比之前的好.从基础讲起.系统清晰,又有编程实践. 在deep learn ...
- 鼠标增强软件StrokeIt使用方法
1 可以从以下网址下载该软件,解压之后有两个文件 http://dl.pconline.com.cn/html_2/1/65/id=7185&pn=0.html 2 先安装英文版的,再安装中文 ...