1、搜索页面:
// 搜索页面功能 function search_keyword(){var game_search_ul=$('.game_search_ul'); var keyword=$('#shop_search').val(); //用户输入的关键词 if (window.localStorage) { localStorage.setItem("search_word", $('#search_word').val()); } else { Cookie.write("search_word", $('#search_word').val()); }$.ajax({ type:'get', url:'http://mj.97tongcheng.com/shop/index.php?act=mobile&op=goodssearch', dataType:'jsonp', jsonp:'callback', success:function (data) { location.href ='shop_list.html?search='+$('#search_word').val();//打开来新页面 }, error:function(data){ alert('error'); } })}
![]()
2、搜索得到的结果页面
//1 . 当打开页面的时候,自动搜索的是在搜索页得到的商品列表 var value = localStorage.getItem("search_word");//接收上一个搜索页面传过来的值 $.ajax({ type:'get', url:'http://mj.97tongcheng.com/shop/index.php?act=mobile&op=goodssearch&search='+value, dataType:'jsonp', jsonp:'callback', success:function (data) { var goods_searchWord= $('#goods_searchWord').val(); var shop_list_conter=$('.shop_list_conter'); data=data.date; $(".shop_list_conter").empty();//清空上次的搜索结果,否则会每次请求,就在上次请求的数据后面添加重复的请求。 $.each(data,function (i) { goods_name=data[i].goods_name; goods_id=data[i].goods_id; goods_jingle=data[i].goods_jingle; goods_image=data[i].goods_image; goods_price=data[i].goods_price; area_name=data[i].area_name;//地址名字 goods_salenum=data[i].goods_salenum; var $list="<li id="+goods_id+">"+ "<img src='"+ goods_image +"'>"+ "<div class='shop_list_right'>"+ "<div class='shop_list_1'><h3>"+goods_name+"</h3><span>825m</span></div>"+ "<p class='shop_list_2'><span>["+area_name+"]</span>"+goods_jingle +"</p>"+ "<div class='shop_list_3'><p class='shop_list_price'>¥"+goods_price+"</p><p class='shop_list_num'>已售<span>" + goods_salenum + "</span></p></div>"+ "</div>"+ "</li>"; shop_list_conter.append($list); }) }, error:function(data){ alert('error'); } }) //2 . 在本页中,当用户输入商家名字的时候 function search_input(){ $.ajax({ type:'get', url:'http://mj.97tongcheng.com/shop/index.php?act=mobile&op=goodssearch&searcht='+$('#goods_searchWord').val(), dataType:'jsonp', jsonp:'callback', success:function(data){ $(".shop_list_conter").empty();//清空上次的搜索结果,否则会每次请求,就在上次请求的数据后面添加重复的请求。 data=data.date; var $shop_list_conter=$('.shop_list_conter'); console.log(data) $.each(data,function (m) { goods_name=data[m].goods_name; goods_id=data[m].goods_id; goods_jingle=data[m].goods_jingle; goods_image=data[m].goods_image; goods_price=data[m].goods_price; area_name=data[m].area_name;//地址名字 goods_salenum=data[m].goods_salenum; var $list="<li id="+goods_id+">"+ "<img src='"+ goods_image +"'>"+ "<div class='shop_list_right'>"+ "<div class='shop_list_1'><h3>"+goods_name+"</h3><span>825m</span></div>"+ "<p class='shop_list_2'><span>["+area_name+"]</span>"+goods_jingle +"</p>"+ "<div class='shop_list_3'><p class='shop_list_price'>¥"+goods_price+"</p><p class='shop_list_num'>已售<span>" + goods_salenum + "</span></p></div>"+ "</div>"+ "</li>"; $shop_list_conter.append($list); }) },error:function (data) { alert('error'); } }) }默认的商品结果
搜索的商家结果