ThinkPHP實(shí)現(xiàn)ajax仿官網(wǎng)搜索功能實(shí)例
本文實(shí)例講述了ThinkPHP實(shí)現(xiàn)ajax仿官網(wǎng)搜索功能的方法。分享給大家供大家參考。
具體實(shí)現(xiàn)方法如下:
后臺(tái)代碼:
function search(){
$keyword = $_POST['search'];
$Goods=M('goods');
//這里我做的一個(gè)模糊查詢(xún)到名字或者對(duì)應(yīng)的id,主要目的因?yàn)槲疫@個(gè)系統(tǒng)是
//商城系統(tǒng)里面用到直接看產(chǎn)品ID
$map['goods_id|goods_name'] = array('like','%'.$keyword.'%');
// 把查詢(xún)條件傳入查詢(xún)方法
if($goods=$Goods->where($map)->select())
{
$this->ajaxReturn($goods,'查詢(xún)成功!',1);
}else{
$this->ajaxReturn($data,"查詢(xún)失敗,數(shù)據(jù)不存在!",0);
}
}
前端代碼:
$(".show_message").hide();
var $search=$('#search_box');
$("#submit_from").click(function(){
if($("#search_box").attr("value")=='')
{
//alert('請(qǐng)輸入文字!');
$(".show_message").html('錯(cuò)誤提示:搜索框文本不能為空!');
$(".show_message").fadeIn(1000);
$(".show_message").fadeOut(1000);
$search.focus();
//return false;
}else{
//開(kāi)始ajax執(zhí)行數(shù)據(jù)
$.ajax({
type: "POST",
url:"/index.php/Goods/search",
data:{
search:$search.val()
},
dataType: "json",
success: function (data) {
if (data.status == 1) {
//alert(data.info);
var html='';
$.each(data.data,function(no,items){
html+='';
});
html+="
'+items.goods_id+' '+items.goods_name+' '+items.add_time+' '+items.brand+' '+items.price+'";
$(".goods-list").html(' ').html(html);
// alert(html);
}
else if (data.status == 0) {
$(".show_message").show();
$(".show_message").html(data.info);
$(".show_message").fadeOut(3000);
// alert(data.info);
return false;
}
}
});
}
});
});
希望本文所述對(duì)大家的ThinkPHP框架程序設(shè)計(jì)有所幫助。
- TP5(thinkPHP5)框架基于ajax與后臺(tái)數(shù)據(jù)交互操作簡(jiǎn)單示例
- ThinkPHP5.1+Ajax實(shí)現(xiàn)的無(wú)刷新分頁(yè)功能示例
- thinkPHP5 ajax提交表單操作實(shí)例分析
- ThinkPHP中使用ajax接收json數(shù)據(jù)的方法
- ThinkPHP結(jié)合AjaxFileUploader實(shí)現(xiàn)無(wú)刷新文件上傳的方法
- thinkphp中AJAX返回ajaxReturn()方法分析
- thinkphp中ajax與php響應(yīng)過(guò)程詳解
- ThinkPHP處理Ajax返回的方法
- thinkPHP+ajax實(shí)現(xiàn)統(tǒng)計(jì)頁(yè)面pv瀏覽量的方法
- thinkphp驗(yàn)證碼的實(shí)現(xiàn)(form、ajax實(shí)現(xiàn)驗(yàn)證)
- thinkPHP5框架實(shí)現(xiàn)基于ajax的分頁(yè)功能示例
- TP5(thinkPHP5)框架使用ajax實(shí)現(xiàn)與后臺(tái)數(shù)據(jù)交互的方法小結(jié)
相關(guān)文章
ThinkPHP模板判斷輸出Empty標(biāo)簽用法詳解
這篇文章主要介紹了ThinkPHP模板判斷輸出Empty標(biāo)簽用法,需要的朋友可以參考下2014-06-06ThinkPHP實(shí)現(xiàn)非標(biāo)準(zhǔn)名稱(chēng)數(shù)據(jù)表快速創(chuàng)建模型的方法
這篇文章主要介紹了ThinkPHP實(shí)現(xiàn)非標(biāo)準(zhǔn)名稱(chēng)數(shù)據(jù)表快速創(chuàng)建模型的方法,對(duì)于采用ThinkPHP操作非標(biāo)準(zhǔn)名稱(chēng)數(shù)據(jù)表的情況非常實(shí)用,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-11-11Thinkphp框架使用list_to_tree 實(shí)現(xiàn)無(wú)限級(jí)分類(lèi)列出所有節(jié)點(diǎn)示例
這篇文章主要介紹了Thinkphp框架使用list_to_tree 實(shí)現(xiàn)無(wú)限級(jí)分類(lèi)列出所有節(jié)點(diǎn),結(jié)合實(shí)例形式分析了thinkPHP遞歸遍歷與數(shù)據(jù)查詢(xún)、排序等相關(guān)操作技巧,需要的朋友可以參考下2020-04-04Laravel解決nesting level錯(cuò)誤和隱藏index.php的問(wèn)題
今天小編就為大家分享一篇Laravel解決nesting level錯(cuò)誤和隱藏index.php的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-10-10