我正在尝试将数据检索到View但失败了。有人会帮帮我吗?这是我的代码: 路线
Route::post('/test',array('as'=>'ajaxTest','uses'=>'TestController@getTestData'));
Route::get('/test',function(){ return View::make('test3');});
TestController
<?php
Class TestController extends BaseController {
public function getTestData()
{
//$companies = People::all();
//http://trirand.com/blog/jqgrid/jqgrid.html
$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction if(!$sidx) $sidx =1;
if(!$sidx) $sidx =1;
// connect to the database
$sql = DB::table('people')->get();
$db = mysql_connect('localhost', 'root', 'mysql')
or die("Connection Error: " . mysql_error());
mysql_select_db('people') or die("Error conecting to db.");
$result = mysql_query("SELECT COUNT(*) AS count FROM invheader a,
clients b WHERE a.client_id=b.client_id");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 ) { $total_pages = ceil($count/$limit); }
else { $total_pages = 0; }
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
$SQL = "SELECT a.id, a.invdate, b.name, a.amount,a.tax,a.total,a.note FROM invheader a, clients b WHERE a.client_id=b.client_id ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error()); $responce->page = $page; $responce->total = $total_pages; $responce->records = $count; $i=0; while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $responce->rows[$i]['id']=$row[id]; $responce->rows[$i]['cell']=array($row[id],$row[invdate],$row[name],$row[amount],$row[tax],$row[total],$row[note]); $i++; }
dd($result);
return Response::json($result);
}
}
查看
<script>
$(document).ready(function () {
jQuery("#list").jqGrid({
//url: '{{ URL::route("ajaxTest") }}' ,
//url: 'ajaxTest',
url: <?php echo URL::to("ajaxTest");?>,
datatype: "json",
colNames:['ID','Name', 'Age'],
colModel:[
{name:'id',index:'id', width:55},
{name:'Name',index:'Name', width:90},
{name:'Age',index:'Age', width:50}
],
rowNum:10,
rowList:[10,20,30],
pager: '#pager2',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
//autowidth: true,
height:280,
viewrecords: true,
multiselect: true,
multiselectWidth: 25,
sortable:true,
caption:"JSON Example"
});
jQuery("#list").jqGrid('navGrid','#pager',{edit:false,add:false,del:false});
});
问题:
1.我如何访问命名路径 ajax.test 和 TestController ?
改变呼叫方式后,路线现在似乎正常工作:
url: <?php echo URL::to("ajaxTest");?>,
但仍然是我的错误:
SyntaxError: missing } after property list
url: http://ecom1/ajaxTest,
2我怎样才能使TestController的getTestData与Laravel一起工作? 非常感谢
答案 0 :(得分:0)
您在javascript中指定的网址为:url: 'ajaxTest'
,而不是指定路线的网址ajax.test
。
你为什么要做mysql_connect
和mysql_query
所有的事情?你不需要和Laravel一起做任何事情。