Cakephp $this->layout = 'ajax'
当我在控制器中声明 $this->layout = 'ajax' 时,我的 css 似乎不起作用。
在我的 view1.ctp 中,我使用 jquery 创建了一个对话框。内容将通过 jquery.ajax() 从 view2.ctp 获取。我创建了 html 类、id 和所有类似于 view1.ctp 的内容。
我收到的内容没问题。问题是我在 view2.ctp 中声明的 id 和类不起作用。简而言之,我得到一个空的对话框设计。
知道如何解决这个问题吗?先感谢您。干杯!
在我的view1.ctp中:
<div id="thisDialog">
<div id="content">
</div>
</div>
<script>
jQuery('.test_box').live('click',function(){
jQuery('#content').empty();
jQuery.ajax({
async:false,
url: '/controller1/view2/'+id //url pointing to my 1controller.php
success:function(data){
jQuery('#content').append(data);
}
});
jQuery('#thisDialog').dialog('open');
});
</script>
这里是controller1.php
function view2($id)
{
$this->layout = 'ajax';
$query = $this->Model->find('all') //somequery here
}
,这里是view2.ctp
<div class='box'>
<div class='title'>
<h5>Title here</h5>
</div>
<div class='contents'>
<table>
<tr>
<td class='head'></td>
<td class='head'></td>
</tr>
<tr>
<td class='alt'>Field content1 here</td>
<td>Fields content2 here</td>
</tr>
</table>
</div>
</div>
my css dosnt seem to work when i declare $this->layout = 'ajax' in my controller.
in my view1.ctp, i created a dialog box using jquery. the content will be getting from view2.ctp via jquery.ajax(). i created the html classes, id and all similar to view1.ctp.
the content im receiving is ok. the problem is that the id and classes i declared within view2.ctp is not working. in short, im getting an empty dialog design.
any idea on how to solve this? thank you in advance. cheers!
in my view1.ctp:
<div id="thisDialog">
<div id="content">
</div>
</div>
<script>
jQuery('.test_box').live('click',function(){
jQuery('#content').empty();
jQuery.ajax({
async:false,
url: '/controller1/view2/'+id //url pointing to my 1controller.php
success:function(data){
jQuery('#content').append(data);
}
});
jQuery('#thisDialog').dialog('open');
});
</script>
here is controller1.php
function view2($id)
{
$this->layout = 'ajax';
$query = $this->Model->find('all') //somequery here
}
here is view2.ctp
<div class='box'>
<div class='title'>
<h5>Title here</h5>
</div>
<div class='contents'>
<table>
<tr>
<td class='head'></td>
<td class='head'></td>
</tr>
<tr>
<td class='alt'>Field content1 here</td>
<td>Fields content2 here</td>
</tr>
</table>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
AJAX 布局是一个简单的空白文件,仅包含您输出的 HTML(或其他内容)片段。它不包含任何样式表,因为样式信息应来自您要插入内容的页面。在调用页面中定义 ID 和类的样式将解决您的问题。
The AJAX layout is a simple blank file which only contains the HTML (or other content) scrap that you output. It does not contain any stylesheets because the style info should come from the page that you are inserting the content into. Defining your styles for the ID and classes in the calling page will solve your problem.
“ajax”布局可以在 cake/libs/view/layouts/ajax.ctp 中找到,其内容是:
这本质上仅输出视图,没有任何周围的 HTML(因此没有 CSS 或 JS)。
The 'ajax' layout can be found in cake/libs/view/layouts/ajax.ctp and it's contents are:
This essentially only outputs the view, without any surrounding HTML (so no CSS or JS).
为什么“ajax”布局需要 CSS?无论如何:
Why would you need CSS for 'ajax' layout? Anyway: