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

首頁 > 編程 > JavaScript > 正文

jQuery中ajax請求后臺返回json數據并渲染HTML的方法

2019-11-19 13:18:48
字體:
來源:轉載
供稿:網友

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數據并渲染HTML的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 正安县| 大宁县| 锡林郭勒盟| 揭西县| 蚌埠市| 大新县| 清丰县| 乐安县| 台中市| 本溪市| 望江县| 河源市| 新巴尔虎右旗| 土默特右旗| 周至县| 曲周县| 蚌埠市| 临汾市| 广西| 大姚县| 綦江县| 许昌县| 兴安县| 龙江县| 那坡县| 成安县| 黑水县| 宝山区| 米易县| 格尔木市| 汉中市| 汝阳县| 重庆市| 济宁市| 滦南县| 南投市| 余干县| 犍为县| 东宁县| 荆门市| 贡嘎县|