gpt4 book ai didi

mysql - Laravel 的 View 的 ajax 命名路由

转载 作者:行者123 更新时间:2023-11-30 00:09:49 25 4
gpt4 key购买 nike

我尝试检索数据以查看但失败。有人会帮我吗?这是我的代码:路线

Route::post('/test',array('as'=>'ajaxTest','uses'=>'TestController@getTestData'));    
Route::get('/test',function(){ return View::make('test3');});

测试 Controller

<?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.testTestController
将调用方式更改为以下后,路线似乎现在可以工作:

url: <?php echo URL::to("ajaxTest");?>,

但仍然给我带来错误:

SyntaxError: missing } after property list


url: http://ecom1/ajaxTest,

2 我怎样才能使 TestController 的 getTestData 以 Laravel 方式工作?非常感谢

最佳答案

您在 JavaScript 中指定的 URL 为:url: 'ajaxTest',而不是指定路由的 URL ajax.test

为什么你要做那些mysql_connectmysql_query的事情?您不需要使用 Laravel 执行任何这些操作。

关于mysql - Laravel 的 View 的 ajax 命名路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24173310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com