0
我使用Cakephp 2.8.0。我的问题是ajax。我不知道如何在我的应用程序中实现ajax。我有李链接的类别,并点击后,我需要删除一些HTML代码,并在我的控制器中找到必要的类别,并得到这个数组在响应HTML和打印它。Galleryphp中加载ajax的图片库
我PhotosController行动:
public function getPhotoByCategory($category = null)
{
$category=$_GET['category'];
debug($category);
$this->render('getPhotoByCategory', 'ajax');
}
我的HTML代码:
<div class="lol">
<ul>
<?php foreach($categories as $category):?>
<li>
<a href="<?php echo $category['Category']['cat_name'];?>" class="lol"><?php echo $category['Category']['cat_name'];?></a>
</li>
<?php endforeach;?>
</ul>
</div>
我的JS代码:
$(".lol").click(function (e) {
e.preventDefault();
var category = $(this).attr("href");
$.ajax({
type: 'get',category,
data: {catyegory:
url: '<?php echo $this->Html->url(array('controller' => 'Photos', 'action' => 'getPhotoByCategory')); ?>',
success: function(response) {
if (response.error) {
alert(response.error);
console.log(response.error);
}
if (response.content) {
$('#target').html(response.content);
}
},
error: function(e) {
alert("An error occurred: " + e.responseText.message);
console.log(e);
}
});
});
请帮我在CakePHP中右AJAX这种情况。