国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表

圖片精選

主站蜘蛛池模板: 夏邑县| 庐江县| 普安县| 冀州市| 伊金霍洛旗| 汾阳市| 都安| 呼伦贝尔市| 龙门县| 太仓市| 德惠市| 邢台市| 廊坊市| 边坝县| 儋州市| 舞阳县| 苏尼特左旗| 镶黄旗| 梓潼县| 古浪县| 临泉县| 云安县| 翁源县| 嵩明县| 和田县| 手游| 彭州市| 纳雍县| 新余市| 兴宁市| 昌平区| 洞口县| 友谊县| 屏边| 沭阳县| 崇信县| 六枝特区| 铜梁县| 临城县| 昌江| 崇信县|