开发者

CakePHP and JQuery function .load()

I am trying to use the JQuery function .load() with cakePHP.

In my JS I have:

$("div.banery_top_lewy").load("www.example.eu/events/drawLargeBanner");

I have also added a RequestHandler component, then in the action drawLargeBanner I have echoed a link with an image. I was expecting that this would load the image into the mentioned div but its loads into the whole page instead.


//edit

Some of you suggested that if the JS is not from the same domain it may not work. Mine was from the same domain although it was not working. My solution to this problem was to change:

$("div.banery_top_lewy").load("www.example.eu/events/drawLarge开发者_如何学编程Banner");

to

$("div.banery_top_lewy").load(".//events/drawLargeBanner");


When you mean loads the whole page, do you mean it loads everything such as

<html
<!-- css bla bla -->
<body>
  <!-- content --> 
</body>
</html>  

If so, try using the ajax.ctp layout that comes with Cake - it outputs just the content.

function drawLargeBanner() {
    $this->layout = 'ajax';
}

// you may need to create this layout, but it's usually found in a default cake install

//ajax.ctp
<?php echo $content_for_layout; ?>

Create your view as normal.

It's essentially a blank layout, for use with ajax, presumably allowing you want you want to achieve.


Try adding this in to your action within your controller:

$this->autoLayout = false;


At the beginning of the action add this

$this->layout = null;

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜