当前位置:Gxlcms > PHP教程 > 请教怎么php怎么返回变量+组装html给ajax

请教怎么php怎么返回变量+组装html给ajax

时间:2021-07-01 10:21:17 帮助过:15人阅读

请问如何php如何返回变量+组装html给ajax
function html($select,$name){
global $pagecon;
$a='1';
$b='2';
$result='';
$result.='
    ';
    while($row=$select->fetch()){
    $result.='
  • ';
    $result.='
      ';
      $result.='

      '.$row['ztname'].'

      ';
      $result.=''. $row['zttype'].'';
      $result.='

      推荐日期:'.$row['zttime'].'

      ';
      }
      $result.='
    ';
    $result.='

    '.$pagecon.'

    ';
    return $result,$a,$b;
    }

需要返回$a变量和$b变量以及一个组装好的$result的html给ajax 请问在不用json的情况下 如果封装给ajax

分享到: 更多


------解决方案--------------------
return "$result,$a,$b";

success:function(json){
a = json.split(',');

------解决方案--------------------
function html($select,$name){
global $pagecon;
$a='1';
$b='2';
$result='';
$result.='
    ';
    while($row=$select->fetch()){
    $result.='
  • ';
    $result.='
      ';
      $result.='

      '.$row['ztname'].'

      ';
      $result.=''. $row['zttype'].'';
      $result.='

      推荐日期:'.$row['zttime'].'

      ';
      }
      $result.='
    ';
    $result.='

    '.$pagecon.'

    ';
    return $result.'--'.$a.'--'.$b;//用--来连接返回
    }


function getData(page){
alert('ok');
$.ajax({
type:'post',
url:'action/test.php',
data: {'pageNum':page-1},
beforeSend:function(){
$("#sss ul").append("
  • loading...
  • ");
    },
    success:function(json){
    var arr=json.split('--');
    $("#sss ul").empty();
    result = arr['0']//获得来自php的变量$result
    total = arr['0']//获得来自php的变量$a
    pageSize = //获得来自php的变量$b
    $("div#sss").html(data);
    },
    complete:function(){ //生成分页条
    getPageBar();
    },
    error:function(){
    alert("数据加载失败");
    }
    });
    }


    希望能帮助你!

    人气教程排行