Both thinkphp and jquery Easyui are good frameworks, and now it's time to combine the two into one and make a simple Ajax call query.
Introduce the Easyui related file in the thinkphp template and set the call to button 3:
<!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head> <title>Easyui app</title> <LinkID= "Easyuitheme"rel= "stylesheet"type= "Text/css"href= "__public__/js/jquery-easyui-1.4.1/themes/{$_cookie.easyuithemename|default="default "}/easyui.css"> <Linkrel= "stylesheet"type= "Text/css"href= "__public__/js/jquery-easyui-1.4.1/themes/default/easyui.css"> <Linkrel= "stylesheet"type= "Text/css"href= "__public__/js/jquery-easyui-1.4.1/themes/icon.css"> <Scripttype= "Text/javascript"src= "__public__/js/jquery-easyui-1.4.1/jquery.min.js"></Script> <Scripttype= "Text/javascript"src= "__public__/js/jquery-easyui-1.4.1/jquery.easyui.min.js"></Script> <Scripttype= "Text/javascript"> $(function(){ //$.messager.alert (' Hint info ', ' Hello,garfield! '); $("#b1"). Click (function(){ $('#test'). HTML ('Button1 Click'); }); $("#b2"). Click (function(){ $('#test'). HTML ('Button2 Click'); }); $("#b3"). Click (function(){ $('#mygrid'). DataGrid ({title:'Hello Garfield', Width: the, //Read data directly //URL: ' __public__/data/datagrid_data1.json ',URL:'{: U ("Index/read")}', columns:[[{field:'ProductID', Title:'Code', Width: -}, {field:'ProductName', Title:'Name', Width: -}, {field:'ListPrice', Title:' Price', Width: -, align:' Right'} ]] }); }); }); </Script> <Scripttype= "Text/javascript"src= "__tmpl__/index/initapp.js"CharSet= "Utf-8"></Script></Head><Body> <ButtonID= ' B1 '>Button1</Button> <ButtonID= ' B2 '>Button2</Button> <DivID= ' Test '>This is a div! </Div> <ButtonID= ' B3 '>Button3</Button> <TableID= ' Mygrid '></Table></Body></HTML>
thinkphp back Controller Add Read method:
<? phpnamespace home\controller;use Think\controller;classIndexcontroller extends Controller {public Function index () {$this->show ('<style type= "Text/css" >*{padding:0, margin:0;} div{padding:4px 48px;} body{background: #fff; font-family: "Microsoft Jas Black"; Color: #333; font-size:24px} h1{font-size:100px; font-weight:normal; margin-bottom:12px;} p{line-height:1.8em; font- size:36px}</style><div style= "padding:24px 48px;" > ','Utf-8'); $this-display (); Public function read () {$total=2; $userlist [0]['ProductID']='Prd1'; $userlist [0]['ProductName']='prdname1'; $userlist [0]['ListPrice']='Ten'; $userlist [1]['ProductID']='Prd2'; $userlist [1]['ProductName']='prdname2'; $userlist [1]['ListPrice']=' -'; $json='{"Total":'. $total.', "Rows":'. Json_encode ($userlist).'}';//important, the EASYUI standard data format, the total number of data and data content in the same JSON echo $json; }}
Note: The foreground template uses a button to invoke the background data query, and the background uses a simple array to return the foreground data format. Note the JSON format of the foreground.
Simple processing of thinkphp+jquery easyui DataGrid query data