ExtJS——AJAX请求数据

index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>


    <link rel="stylesheet" type="text/css" href="resources/css/ext-all.css" />
    <script type="text/javascript" src="ext-all-debug.js"></script>
    <script type="text/javascript" src="ext-all.js"></script>
    <script type="text/javascript" src="bootstrap.js"></script>
</head>
<body>
<script type="text/javascript">
Ext.onReady(function(){
    var panel = new Ext.Panel({  //没有show方法,调用报错显示innerHTML为空
        title:'AJAX数据',
        width:200,
        height:400,
        frame:true,
        id:'panel'
    });
    var template = new Ext.XTemplate('<tpl for=".">',
                       '<table  id="template">',
                           '<tr><td>编号:</td><td>{id}</td></tr>',
                           '<tr><td>姓名:</td><td>{name}</td></tr>',
                           '<tr><td>生日:</td><td>{brithday}</td></tr>',
                           '<tr><td>身高:</td><td>{height}</td></tr>',
                           '<tr><td>性别:</td><td>{sex}</td></tr>',
                           '<tr><td valign="top">描述:</td><td>{discribe}</td></tr>',
                        '</table><hr/></tpl>');
  //ajax获取数据
  Ext.Ajax.request({
    url:'php/ajax.php',
    method:'post',
    params:{id:1},
    success:function(response,options){
        var str='';
        for(i in options){
            str+='options参数名称:' + i+';参数值:'+options[i]+";<br/>"
        }
       // Ext.MessageBox.alert('提示',str);
        var responseJson = Ext.JSON.decode(response.responseText);
        template.compile();//编译模板。
        template.overwrite(panel.body,responseJson);//将数据填充到模板,将模板和数据转化为html放到panel.body中
    },   
    failure:function(){
        Ext.MessageBox.alert('提示','系统错误!!');
    }


  });
//创建窗体
    var win = new Ext.Window({
        title: '窗口',
        id: 'window',
        width: 476,
        height: 374,
        resizable: true,
        modal: true,
        closable: true,
        maximizable: true,
        minimizable: true,
        items: [panel]
    });
    win.show();
});
</script>
</body>
</html>
ajax.php
<?php
$id=$_POST['id'];//post传过来,就用post取
if($id=='1'){
  $res=array(
  	array('id'=>1,'name'=>'小二','birthday'=>'2011/2/1','height'=>'180cm','sex'=>'女','discribe'=>'smiling girl!'),
   	array('id'=>2,'name'=>'三三','birthday'=>'2011/2/1','height'=>'180cm','sex'=>'女','discribe'=>'smiling girl!'),

  	);
}else{
  $res=array('success'=>false);
}  

echo json_encode($res); 
?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值