php语法之ajax的运用方法

php的ajax应该怎么运用,下面编程教程网小编给大家详细讲解一下!

javascript端

var cityInfo=$('#cityInfo').val();
var typeInfo=$('#typeInfo').val();
if(!(cityInfo==''&& typeInfo=='')){
  $.ajax({
    url:'/index.php?m=member&c=index&d=111',
    type:'POST',
    dataType:'json',
    data: {cityInfo:cityInfo,typeInfo:typeInfo},
    success:function(data){
      var str='';
      for(i in data){
        str += "<div class='caseIntroduce'>";
        str += "<a href='index.php?m=member&c=index&a=exchange_show&type=accept&id="+data[i]['id']+"'>";
        str += "<div class='caseinfo1'>";
        str += "<span class='casetitle'>"+data[i]['title']+"...</span>";
        str += "</div>";
        str += "<div>";
        str += "<span class='caseblue'>"+data[i]['classification']+"</span>";
        str += "<span>金额:"+data[i]['accountMoney']+"</span>";
        str += "<span>费用:"+data[i]['entrustcost']+"元</span>";
        str += "<span>"+data[i]['linkage']+"</span>";
        str += "<span>"+data[i]['receivetime']+"</span>";
        str += "</div>";
        str += "</a>";
        str += "</div>";
      }
      $(".caseCenter").html(str);
    }
  
  })
}

php端

public function receive_search(){
  $cityInfo=$_POST['cityInfo'];
  $typeInfo=$_POST['typeInfo'];
  $sqlCity=$cityInfo == '' ? '' :"linkage='$cityInfo'";
  $sqlType=$typeInfo == '' ? '' : "classification='$typeInfo'";
  if(!empty($sqlCity)&&!empty($sqlType)){
    $sql=$sqlCity.'AND '.$sqlType;
  }else{
    $sql=$sqlCity.$sqlType;
  }
  $order = 'updatetime desc';
  $catid = 181;
  if(!$this->set_modelid($catid)) return false;
  $datas = $this->db_con -> select($sql,'*', '', $order, '', '');
  foreach($datas as $key=>$val){
    $datas[$key]['title']=displayPart($val['title'],15);
    $datas[$key]['classification']=get_linkage($val['classification'],6650,'-',1);
    $datas[$key]['accountMoney']=get_linkage($val['accountMoney'],6766,'-',1);
    $datas[$key]['linkage']=sliceArea(get_linkage($val['linkage'],3360,'-',1));
    $datas[$key]['receivetime']=date('Y-m-d',$val['receivetime']);
  }
  echo json_encode($datas);
  exit;
}
以上是编程学习网小编为您介绍的“php语法之ajax的运用方法”的全面内容,想了解更多关于 php入门 内容,请继续关注编程基础学习网。

本文标题为:php语法之ajax的运用方法

基础教程推荐