Php 通过jQuery使用大量html刷新DIV
很抱歉迟到了,而且没有发布代码也太草率了 因此,它在这里起作用: 在索引页面中,有一些类别,用户可以使用这些类别在显示的图像之间进行过滤。 当用户过滤图像时,我获取图像并通过jQueryAjax将它们传递给我的控制器,在那里我获取新的过滤图像。 以下是AJAX方法的外观: 在“filter_this”变量中,变量被存储Php 通过jQuery使用大量html刷新DIV,php,jquery,ajax,Php,Jquery,Ajax,很抱歉迟到了,而且没有发布代码也太草率了 因此,它在这里起作用: 在索引页面中,有一些类别,用户可以使用这些类别在显示的图像之间进行过滤。 当用户过滤图像时,我获取图像并通过jQueryAjax将它们传递给我的控制器,在那里我获取新的过滤图像。 以下是AJAX方法的外观: 在“filter_this”变量中,变量被存储 $.ajax({ 'type': 'post', 'url': '*controllername*', 'datatype': 'html',
$.ajax({
'type': 'post',
'url': '*controllername*',
'datatype': 'html',
'data': {'categories': filter_these},
success: function(response){
window.alert(response);
}
});
在我的控制器中,我得到了存储在变量中的新图像。在jQuery中传递时,图像处于“response”变量中。现在我需要找到一种方法,用新的图像重新加载页面的图像部分。如果我不需要在它周围应用大量HTML内容,这可以很容易做到
所以我想知道的是如何用新图像重新加载页面的这一部分
我曾想在一个页面上回显这些图片,但在使用CodeIgniter时,我似乎找不到答案
或者在我的控制器中重复,这不是一个好的工作方式。帮助将不胜感激。Jquery函数,该函数将(load_image.php)加载到某个div中
$('#filter_id').click( function(){
// grabs some info so we know what the image is
var aa = $('#image').val();
// clears the div before loading
$('#div_id').empty();
// loads the php page into the div
$('#div_id').load('load_image.php?imagename='+aa);
});
load_image.php
<php
$imagename = $_GET['imagename'];
?>
<img src="/images/<?php echo $imagename;?>">
">
您可以这样做:
<div id="imagesContainer">
<img src="image1.jpg" title="Fred" />
<img src="image2.jpg" title="Dave" />
</div>
签出此JSFIDLE:(在本例中,您可以搜索Mario、Zelda或Sonic)您可以提供一些代码吗?“我如何在不使用javascript/jquery添加所有html的情况下执行此操作?”…您是否询问如何在不使用编程语言的情况下进行编程?可能您可以使用$。例如,您可以向图像添加一些类(或数据属性中的对象)作为标记,然后使用过滤器仅显示所需的图像(用户选择(.s)。但为了获得更好的答案,您需要向我们提供更多详细信息,并可能发布一个小标题。
$('input#filter').keyup(function() {
if($(this).val() == '') { //If the filter is blank
$('div#imagesContainer > img').show(); //Show all the images
} else { //If the filter is not blank
$('div#imagesContainer > img').hide(); //Hide all of the images to start with
$('div#imagesContainer > img[title^="'+$(this).val()+'"]').show(); //Show the matching images
}
});