gpt4 book ai didi

javascript - 黑洞请求 Cakephp

转载 作者:行者123 更新时间:2023-11-30 13:17:01 24 4
gpt4 key购买 nike

在我的索引页上,我的表格的每一行都有复选框。

为了编辑选定的项目,我使用 javascript/jquery 获取复选框的类,构建一个 id 数组,然后将其发布到我的 Controller 中的编辑选定的方法。

现在,这一切都完美无缺,但是当在我的 App Controller 中启用安全性时,我的帖子变成了黑洞并且没有发布数组。

这是我的 index.ctp 文件:

<table id="indexTable">
<thead><tr>
<th> <?php echo $this->Form->checkbox('select_all', array('value' => 'select_all')); ?> </th>
<th> <?php echo $this->Paginator->sort('id', 'ID'); ?> </th>
<th> <?php echo $this->Paginator->sort('name', 'Name'); ?> </th>
<th>Auto Offset </th> <th>UTC Offset Sec </th> <th>In Month </th>
<th>In Week </th> <th>In Dow </th> <th>In Hour </th> <th>Out Month </th>
<th>Out Week </th> <th>Out Dow </th> <th>Out Hour </th> <th>Offset Sec </th>
<th>DST Ref </th> <th>Actions </th>
</tr></thead>

<tbody>

<?php
$this->Form->create('LocalClock');
foreach($localClocks as $LocalClock) { ?>
<tr>
<td> <?php echo $this->Form->checkbox('LocalClocks'.$LocalClock['LocalClock']['id'], array('value' => $LocalClock['LocalClock']['id'], 'hiddenField' => false));?> </td>
<td> <?php echo $LocalClock['LocalClock']['id']; ?> </td>
<td> <?php echo $LocalClock['LocalClock']['name']; ?> </td>
<td> <?php echo $LocalClock['LocalClock']['auto_offset']; ?> </td>
</tr>
<?php } ?>
</tbody>
</table>

</div>

<!-- This <div> contains all the actions that can be performed on the Local Clocks. -->
<div>
<p>

<span style="float: left">
<?php echo $this->Html->link(__('Edit All Items'), array('action' => 'editAll'), array('class' => 'link'));?> &nbsp;&nbsp;
</span>

<span style="float: left">
<?php echo $this->Html->link(__('Edit Selected Items'), array('action' => 'lceditSelected'), array('class' => 'general_dialog'));?> &nbsp;&nbsp;
</span>

<span style="float: right">
<?php echo $this->Html->link(__('Delete Selected Items'), array('action' => 'deleteSelected'), array('class' => 'general_dialog'));?> &nbsp;&nbsp;
</span>
<?php $this->Form->end(); ?>

</p>
</div>

我去掉了一些不重要的东西。问题出在我选择的编辑和删除选择的功能上。

这是等待他们点击然后构建数组以发布到 Controller 操作的 javascript 代码:

$('.general_dialog').live('click', function()
{
$.ajaxSetup({ async: false });

var $selDialog = $("#general_dialog").dialog(
{
autoOpen: false,
modal: true,
});

var postInfo = $('#LocalClockIndexForm').serialize();
$.ajax({
url: $(this).attr('href'),
type: "post",
data: postInfo,
success: function (response)
{
alert('success');
},
error: function()
{
alert("failed");
}
});
$selDialog.load($(this).attr('href'), function ()
{
$selDialog.dialog('open');
});
return false; // Ensure the controller does not redirect to the actual edit page
});

如果您能提供任何有关如何使其正常工作而不会陷入黑洞的帮助,我们将不胜感激。

提前致谢

----------------------------------------编辑---- ------------------------------------------我将 $this->Form->create('LocalClock')$this->Form->end() 添加到表中,然后我切换了 $.post () 和 $.ajax() 调用。

如果我发送序列化表单,我不会遇到黑洞,但当我查看发布的数据时,它不包含任何复选框 ID。

最佳答案

您的示例缺少表单标签。

您需要使用表单助手创建和结束表单,以确保安全 token 包含在表单生成中:

$this->Form->create();
// Other form elements here.
$this->Form->end();

关于javascript - 黑洞请求 Cakephp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11694865/

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