php框架

 首页 > php框架 > ThinkPHP > ThinkPHP中ajax仿官网搜索功能 - Thinkphp

ThinkPHP中ajax仿官网搜索功能 - Thinkphp

分享到:
【字体:
导读:
          后台代码: 搜索,如果在1不在0functionsearch(){$keyword=$_POST[ 39;search 39;];$Goods=M( 39;goods 39;); 这里我做的一个模糊查询...

ThinkPHP中ajax仿官网搜索功能

后台代码:

  1. //搜索,如果在1不在0 
  2. function search(){ 
  3.     $keyword = $_POST['search']; 
  4.     $Goods=M('goods'); 
  5.   //这里我做的一个模糊查询到名字或者对应的id,主要目的因为我这个系统是 
  6.   //商城系统里面用到直接看产品ID 
  7.     $map['goods_id|goods_name']  = array('like','%'.$keyword.'%'); 
  8.     // 把查询条件传入查询方法 
  9.     if($goods=$Goods->where($map)->select()) 
  10.      { 
  11.               $this->ajaxReturn($goods,'查询成功!',1); 
  12.      }else
  13.               $this->ajaxReturn($data,"查询失败,数据不存在!",0); 
  14.          } 
  15.      } 

前端代码:

  1. $(document).ready(function(){ 
  2.    $(".show_message").hide(); 
  3.    var $search=$('#search_box'); 
  4.    $("#submit_from").click(function(){ 
  5.     if($("#search_box").attr("value")==''
  6.     { 
  7.         //alert('请输入文字!'); 
  8.         $(".show_message").html('错误提示:搜索框文本不能为空!'); 
  9.         $(".show_message").fadeIn(1000); 
  10.         $(".show_message").fadeOut(1000); 
  11.         $search.focus(); 
  12.         //return false; 
  13.     }else
  14.         //开始ajax执行数据 
  15.         $.ajax({ 
  16.             type: "POST"
  17.             url:"/index.php/Goods/search"
  18.             data:{ 
  19.                 search:$search.val() 
  20.             }, 
  21.             dataType: "json"
  22.             success: function (data) { 
  23.     if (data.status == 1) { 
  24.             //alert(data.info); 
  25.             var html=''
  26.                     $.each(data.data,function(no,items){     
  27.                     html+=''
  28.                     }); 
  29.                     html+=" 
  30. '+items.goods_id+' '+items.goods_name+' '+items.add_time+' '+items.brand+' '+items.price+'";     
  31.                      $(".goods-list").html(' ').html(html); 
  32.                    // alert(html); 
  33.     } 
  34.     else if (data.status == 0) { 
  35.         $(".show_message").show(); 
  36.         $(".show_message").html(data.info); 
  37.                     $(".show_message").fadeOut(3000); 
  38.     //    alert(data.info); 
  39.           return false; 
  40.         } 
  41.       } 
  42.          }); 
  43.     } 
  44.   }); 
  45. }); 
分享到:
ThinkPHP实现支付宝接口功能 - Thinkphp
ThinkPHP实现支付宝接口功能 最近做系统,需要实现在线支付功能,毫不犹豫,选择的是支付宝的接口支付功能,这里我用的是即时到帐的接口,具体实现的步骤如下: 一、下载支付宝接口包 下载地址:https://b.alipay.com/order/productDetail.htm?productId=2012111200373124&tabId=4#ps-tabinfo-has...
Thinkphp框架学习 - Thinkphp
Thinkphp框架学习 Thinkphp学习中,有两个环境,wampServer和appServ两个环境,他们的目录分别在安装目录的wamp和app目录下的www目录下。 无论是哪一个PHP开发环境,都要很好的配置开发环境。一般在浏览器上输入http://localhost回车访问即可,或者在后面加上你的端口号,默认的是80,你可以修改成...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……