我正在尝试使用服务器端处理在php项目上实现jquery数据表,但是分页不起作用,我在firebug控制台中没有错误.
页面简单直接,这里是html代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-2.2.3/dt-1.10.12/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-2.2.3/dt-1.10.12/datatables.min.js"></script>
</head>
<body>
<table class="table">
<thead>
<tr>
<th col-data="item_id">Item Id</th>
<th col-data="name">Name</th>
</tr>
</thead>
</table>
<script type="text/javascript">
$(document).ready(function() {
var dataTable = $('.table').DataTable( {
"processing": true,
"serverSide": true,
"buttons": [],
"order": [],
"ajax":{
url :"{{ url('stock_acc_get') }}", // json datasource
type: "post",
}
} );
} );
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是在服务器上发布的数据(在firebug控制台中查看):
columns[0][data] 0
columns[0][name]
columns[0][orderable] true
columns[0][search][regex] false
columns[0][search][value]
columns[0][searchable] true …Run Code Online (Sandbox Code Playgroud) 如何Button在使用javascript更改属性值后检索自定义属性?
例:
Asp文件
<asp:Button ID="Button1" runat="server" Text="Button1" />
<asp:Button ID="Button2" runat="server" Text="Button2" OnClick="Button2_Click" />
<script type="text/javascript">
var btn1 = '#<% Button1.ClientID %>';
var btn2 = '#<% Button2.ClientID %>';
$(btn1).click(function(e) {
e.preventDefault();
$(btn2).attr("actIndex", "2");
});
</script>
Run Code Online (Sandbox Code Playgroud)
CodeBehind文件
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
Button2.Attributes.Add("actIndex","1");
}
protected void Button2_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
// this should be 2 if button1 has been clicked
string actIndex = btn.Attributes["actIndex"];
}
Run Code Online (Sandbox Code Playgroud)
如果我单击Button1然后单击Button2该actIndex …
我为我的 symfony2 项目创建了一个控制台命令,我想从控制器执行它而不阻塞控制器输出(在后台)。
通常是这样执行的:
$application = new Application($kernel);
$application->setAutoExit(true);
// AppBundle/Command/UpdateStockCommand.php
$input = new ArrayInput(array(
'command' => 'update:stock',
));
$output = new NullOutput();
$application->run($input, $output);
Run Code Online (Sandbox Code Playgroud)
但是像这样运行,用户将不得不等待任务完成,这可能需要几分钟。
一个解决办法是:
$kernel = $this->get('kernel');
$process = new \Symfony\Component\Process\Process('nohup php '. $kernel->getRootDir() .'/console update:stock --env='. $kernel->getEnvironment() .' > /dev/null 2>&1 &');
//$process->start();
$process->run();
Run Code Online (Sandbox Code Playgroud)
没有给出错误,控制器呈现输出,但不执行任务。
另一种解决方案是:
exec('/usr/bin/php '.$this->get('kernel')->getRootDir().'/console update:stock --env=dev > /dev/null 2>&1 &');
Run Code Online (Sandbox Code Playgroud)
在此处找到Symfony2 - 进程启动 symfony2 命令, 但不适用于我的示例。
javascript ×2
asp.net ×1
c# ×1
datatables ×1
jquery ×1
pagination ×1
php ×1
postback ×1
symfony ×1