例如:比如我的某个url,
 http://127.0.0.1/xxx/xxx.php?action=gg是去执行xxx.php中某段代码if ($action == ....) {
  ...
  ...
   
  return $arr;
}
。我在php代码中,怎样获取这个url所返回的 $arr

解决方案 »

  1.   

    如果是同一个域下面请用ajax来做,如果不是,用文件流得到返回的页面内容。你的action里面不能return,只能打印到页面上
      

  2.   

    你是在那个页面获取呀?  session试过吗?
      

  3.   

    以JSON传出,给你个实例:
    <?php
    if (!empty($_GET['ajax'])) {
        $arr = array(array(0,1,2,3),array(10,11,12,13),array(20,21,22,23));
        echo json_encode($arr);
        exit;
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title> new document </title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="generator" content="editplus" />
        <meta name="author" content="JnKc" />
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <style type="text/css">
            *{font-size:12px;}
        </style>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    </head>
    <body>
    <script type="text/javascript">
    $.getJSON('?ajax=true',{},function(data){alert('data[1][2]='+data[1][2]);});
    $.get('?ajax=true',{},function(data){eval('data='+data);alert('data[1][3]='+data[1][3]);});
    </script>
    </body>
    </html>
      

  4.   

    A页面:<script>
    function createRequest(){
        var request;
        if(window.XMLHttpRequest){ 
            request = new XMLHttpRequest();
        } else if(window.ActiveXObject){ 
            request = new ActiveXObject("Microsoft.XMLHTTP");
        }
        return request;
    }function get(){
        var ajax=createRequest();
        var action="gg";
        var url = "mgr/getDiqu.php?city="+city;
        var url="http://127.0.0.1/xxx/xxx.php?action"+action;
        ajax.open("GET",url,true);
        ajax.onreadystatechange = function () {
            if (ajax.readyState == 4 && ajax.status==200) {
                    updateDiqu(ajax.responseText);
            }
        }
        ajax.send(null);
    }
    function updateDiqu(str){
        alert(str);
    }
    </script>
    B页面:(http://127.0.0.1/xxx/xxx.php)
    if ($action == ....) { 
      ... 
      ... 
      
      return $arr; 

    。 
      

  5.   

    饿  写错了!把B页面的$arr 改成$str 让后在echo $str; 就OK了