zend中的flexigrid问题

时间:2010-05-18 17:20:26

标签: json zend-framework

我有一个页面 post2.php ,它打印json数组,如

{
page: 1,
total: 239,
rows: [
{id:'239',cell:['239','ZW','ZIMBABWE','Zimbabwe','ZWE','716']},
{id:'238',cell:['238','ZM','ZAMBIA','Zambia','ZMB','894']},
{id:'237',cell:['237','YE','YEMEN','Yemen','YEM','887']},
{id:'236',cell:['236','EH','WESTERN SAHARA','Western Sahara','ESH','732']},
{id:'235',cell:['235','WF','WALLIS AND FUTUNA','Wallis and Futuna','WLF','876']},
{id:'234',cell:['234','VI','VIRGIN ISLANDS, U.S.','Virgin Islands, U.s.','VIR','850']},
{id:'233',cell:['233','VG','VIRGIN ISLANDS, BRITISH','Virgin Islands, British','VGB','92']},
{id:'232',cell:['232','VN','VIET NAM','Viet Nam','VNM','704']},
{id:'231',cell:['231','VE','VENEZUELA','Venezuela','VEN','862']},
{id:'230',cell:['230','VU','VANUATU','Vanuatu','VUT','548']}]
}

并且在zend视图中我试图像

那样做
$(document).ready(function(){

        $("#flex1").flexigrid
                        (
                        {
                        url: '/public/**post2.ph**p',
                        dataType: 'json',
                        colModel : [
                                {display: 'ID', name : 'id', width : 40, sortable : true, align: 'center'},
                                {display: 'ISO', name : 'iso', width : 40, sortable : true, align: 'center'},
                                {display: 'Name', name : 'name', width : 180, sortable : true, align: 'left'},
                                {display: 'Printable Name', name : 'printable_name', width : 120, sortable : true, align: 'left'},
                                {display: 'ISO3', name : 'iso3', width : 130, sortable : true, align: 'left', hide: true},
                                {display: 'Number Code', name : 'numcode', width : 80, sortable : true, align: 'right'}
                                ],
                        buttons : [
                                {name: 'Add', bclass: 'add', onpress : test},
                                {name: 'Delete', bclass: 'delete', onpress : test},
                                {separator: true},
                                {name: 'A', onpress: sortAlpha},
                                ],
                        searchitems : [
                                {display: 'ISO', name : 'iso'},
                                {display: 'Name', name : 'name', isdefault: true}
                                ],
                        sortname: "id"
                        sortorder: "asc",
                        usepager: true,
                        title: 'Countries',
                        useRp: true,
                        rp: 10,
                        showTableToggleBtn: true,
                        width: 700,
                        height: 255
                        }
                        );  

});

这会很好地打印出flexigrid布局..但是永远不会得到data.it一直在告诉处理。 在json数组或flexigrid调用中存在一些问题...或者在使用json的zend中。

有任何建议可以尝试解决这个问题吗?

我也尝试了这样

$.post("/public/server_processing1.php",{},function(data){
alert('hai');
alert(data);
}, "json");

它甚至没有警告海..

完整的post2.php代码是这样的

<?
error_reporting(1);
function runSQL($rsql) {
        $hostname = "localhost";
        $username = "root";
        $password = "root";
        $dbname   = "hms1";
        $connect = mysql_connect($hostname,$username,$password) or die ("Error: could not connect to database");
        $db = mysql_select_db($dbname);
        $result = mysql_query($rsql) or die ('test');
        return $result;
        mysql_close($connect);
}

function countRec($fname,$tname,$where) {
$sql = "SELECT count($fname) FROM $tname $where";
$result = runSQL($sql);
while ($row = mysql_fetch_array($result)) {
return $row[0];
}
}
$page = $_POST['page'];
$rp = $_POST['rp'];
$sortname = $_POST['sortname'];
$sortorder = $_POST['sortorder'];

if (!$sortname) $sortname = 'pa_name';
if (!$sortorder) $sortorder = 'desc';
                if($_POST['query']!=''){
                        $where = "WHERE `".$_POST['qtype']."` LIKE '%".$_POST['query']."%' ";
                } else {
                        $where ='';
                }
                if($_POST['letter_pressed']!=''){
                        $where = "WHERE `".$_POST['qtype']."` LIKE '".$_POST['letter_pressed']."%' ";
                }
                if($_POST['letter_pressed']=='#'){
                        $where = "WHERE `".$_POST['qtype']."` REGEXP '[[:digit:]]' ";
                }
$sort = "ORDER BY $sortname $sortorder";

if (!$page) $page = 1;
if (!$rp) $rp = 10;

$start = (($page-1) * $rp);

$limit = "LIMIT $start, $rp";
$sql = "SELECT pa_id,pa_name,pa_pd_patient_id,pa_name FROM patient_appointment $where $sort $limit";
$result = runSQL($sql);

$total = countRec('pa_id','patient_appointment',$where);

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");
$json = "";
$json .= "{\n";
$json .= "page: $page,\n";
$json .= "total: $total,\n";
$json .= "rows: [";
$rc = false;
while ($row = mysql_fetch_array($result)) {
if ($rc) $json .= ",";
$json .= "\n{";
/*$json .= "cell:['".$row['pa_name']."'";
$json .= ",'".addslashes($row['time'])."'";
$json .= ",'".addslashes($row['pa_um_id'])."'";
$json .= ",'".addslashes($row['pa_pd_patient_id'])."']";*/
$json .= "id:'".$row['pa_id']."',";
$json .= "cell:['".$row['pa_id']."','".$row['pa_name']."'";
$json .= ",'".addslashes($row['pa_pd_patient_id'])."']";

$json .= "}";
$rc = true;
}
$json .= "]\n";
$json .= "}";
echo $json;
?>

1 个答案:

答案 0 :(得分:0)

我猜你正在使用IE浏览器。如果是这样,IE不喜欢<div id="flex1"></div>容器。将其更改为<table id="flex1"></table>,一切正常。