ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 调用AJAX获取文章数据 View: 页面功能:选项卡的数据是JQ结合AJAX操作获取文章数据,页面加载默认请求获取li第一条的数据 > \themes\humen\portal\index.html <section> <div class="fzscyq"> <div class="fzscyq_k clearfix"> <div class="fzscyq_kl"> <h4 class="fzscyq_kl_bt">虎门服装市场及园区<span>Humen garment market and park</span><a href="{:cmf_url('portal/List/index', ['id' =>57])}" target="_blank">查看更多</a></h4> <div class="fzscyq_kl_nr clearfix"> <div class="fzscyq_kl_nr_lm"> <ul class="clearfix" id="fzscyq_kl_nr_lm"> <portal:articles order="is_top DESC" categoryIds="57" limit="5"> <li id="{$vo.id}"><p>{$vo.post_title}</p></li> </portal:articles> </ul> </div> <div class="fzscyq_kl_nr_nr" id="fzscyq_kl_nr_nr"> </div> </div> </div> <script type="text/javascript"> $("#fzscyq_kl_nr_lm > li").click(function(){ var rurl = "{:url('portal/Article/getwz')}"; var id = $(this).attr('id'); $.ajax({ url: rurl, type: "post", dataType: "json", data: {id: id }, success: function (data) { // console.log(data); var jg="<div class=\"fzscyq_kl_nr_nrk clearfix sublist\" >"; jg +="<div class=\"fzscyq_kl_nr_nrkl clearfix\"><img src="+ data.data.imgurl +"></div>"; jg +="<div class=\"fzscyq_kl_nr_nrkr clearfix\"><div class=\"fzscyq_kl_nr_nrkrt\">"; jg += data.data.post_content ; jg +="</div>"; jg +="<a href="+data.data.url +" target=\"_blank\">查看详情</a></div></div>"; $('#fzscyq_kl_nr_nr').html(jg); } }); }); $("#fzscyq_kl_nr_lm > li")[0].click(); </script> <div class="fzscyq_kr"> <h4>推荐企业</h4> <ul class="clearfix"> <portal:articles order="is_top DESC" categoryIds="56" limit="9"> <li class="clearfix"><i>推</i><p><a href="{:url('portal/Article/index',array('id'=>$vo.id))}" target="_blank">{$vo.post_title}</a></p></li> </portal:articles> </ul> </div> </div> </div> </section> Controller: > \app\portal\controller\ArticleController.php /** * 获取文章 * @return [type] [description] */ public function getwz() { $id = $this->request->param('id'); if (empty($id)) { $this->error('文章不存在!'); }else{ $postModel = new PortalPostModel(); $data = $postModel->where('id', $id)->find(); $url = cmf_url('portal/Article/index', ['id' => $id], true, true); $img = cmf_get_image_url($data['thumbnail']); $data['url'] = $url; $data['imgurl'] = $img ; //$this->success("OK",,$data); return json(['data'=>$data]); } }