国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

jQuery中ajax請求后臺返回json數(shù)據(jù)并渲染HTML的方法

2024-05-06 15:32:00
字體:
供稿:網(wǎng)友

html實例

<table border="0" class="restaurant_food" cellspacing="0" cellpadding="1">  <input type="text" name="dishes" value="" class="seek_product" placeholder="請輸入菜名"/>  <button type='button' class="btn_nor" onclick="seek_product()">搜索</button>  <tr>    <th width="30%">序號</th>    <th width="70%">菜名</th>  </tr>  <tr data-id="">    <td></td>    <td class="tl"> <p></p></td>  </tr></table>

jquery實例

function seek_product(){  var product = $('.seek_product').val();  $.ajax({    type:'get',    url:'/Cash/Index/seek_product',    data:{name:product},    success:function(res){      var data = eval('('+res+')');      var len = data.length;      var cm = "";      if(len > 0){        for(var i = 0; i < len; i++){          cm += '<tr data-id='+data[i]['id']+'>';          cm += '<td>';          cm += i+1;          cm += '</td>';          cm += '<td class="tl">';          cm += '<p>'+data[i]["name"]+'</p>';          cm += '</td>';          cm += '</tr>';          console.log(cm);          $('.restaurant_food').html(cm);        }      }else{        $('.restaurant_food').html('抱歉,沒有這道菜!');      }    }  })}

php實例

//搜索菜public function seek_product(){  $shop_id = session("cashShopId");  $name = I('get.name');  $map['name'] = array('like','%'.$name.'%');  $map['shop_id'] = $shop_id;  $map['status'] = 1;  $productList = M('product')->field('id,name')->where($map)->select();  echo json_encode($productList);}

以上這篇jQuery中ajax請求后臺返回json數(shù)據(jù)并渲染HTML的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持錯新站長站。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 巩留县| 历史| 新蔡县| 定州市| 麻栗坡县| 龙陵县| 锡林浩特市| 香格里拉县| 上饶县| 南雄市| 盐亭县| 息烽县| 平利县| 南漳县| 潞城市| 新平| 揭西县| 蚌埠市| 吴堡县| 汉阴县| 铜川市| 磴口县| 湄潭县| 德格县| 宜黄县| 林甸县| 建瓯市| 江门市| 双辽市| 霍州市| 大城县| 德令哈市| 仲巴县| 长兴县| 哈密市| 静安区| 鄂州市| 福清市| 高邮市| 新郑市| 高邮市|