redirect and ajax request - El Forum - 04-15-2011
[eluser]amipaxs[/eluser]
Hello,
I have the following scenario, I am implementing a search box in the header, i use ajax to load results from db on the middle colum div="middle-column" , it works perfect! (Image 1)
the Publish section of the site doesn't contain neither sidebar menu nor middle-colum, it only contains a wide div (image 2) in contrast to the other pages which contains side-bar menu, middle-column,etc.
any suggestions, should i redirect to index so i'll have sidemenu and middle column available or should i load all the divs present in Index again in the publish section through ajax.?
Thanxs in advance
redirect and ajax request - El Forum - 04-15-2011
[eluser]toopay[/eluser]
What template library you are using? I think this is a "design" stuff, not ajax problems.
redirect and ajax request - El Forum - 04-16-2011
[eluser]amipaxs[/eluser]
hi,
I don't use a template library , I use my own template view
Code: <div id="header">
<?php $this->load->view('header'); ?>
</div>
<!--- CONTENIDO --->
<?php if (isset($contenido)) { ?>
<!---inicio contenido--->
<div id="content">
<div id="side-menu">
<?php echo $this->load->view('side_menu'); ?>
</div>
<div id="content-middle">
<?php echo $this->load->view($contenido); ?>
</div>
<div id="content-right">
<?php echo $this->load->view('mod_derecha');?>
</div>
</div>
<!---fin contenido--->
<?php }else if (isset($contenido2)) { ?>
<div id="content">
<div id="content-wide">
<?php echo $this->load->view($contenido2); ?> //use this to load the publish page
</div>
</div>
<?php }else {
echo "<h2> No hay contenido visible </h2>";
} ?>
<!--- PIE DE PAGINA --->
<div id="footer">
<div class="center" >
<?php echo $this->load->view('footer'); ?>
</div>
</div>
redirect and ajax request - El Forum - 04-17-2011
[eluser]toopay[/eluser]
How your controller looks like?
redirect and ajax request - El Forum - 04-19-2011
[eluser]amipaxs[/eluser]
controller:
Code: function search_ajax(){
$wanted = $this->input->post('busca');
$data['buscados']= $this->MFondos->searchWallpapers($wanted);
$data = json_encode($data['buscados']);
echo $data;
}
Jquery :
Code: /*************** Search box *****************/
$(document).ready(function() {
$('#form-search').submit(function(e){
e.preventDefault();
var url = base_url+'portal/search_ajax';
var busca = $('#search').attr('value');
var path = [removed].pathname.split("/");
if(path[3] == 'publish'){
[removed].replace(base_url+'portal/index'); // Problem here!
}
$.post(url, {'busca':busca },
function(data){
//$('#wrapper-index').empty();
result = eval('('+ data +')');
if(result!=''){
var html = '<div id="wrapper-index">';
$.each(result, function(entryIndex, entry){
html += '<div class="pic-box">';
html += '<a href="'+ base_url+">';
html += '<img src="'+ base_url+entry['ruta']+ '" width="130" height="110"></a>';
html += '<a href="'+ base_url+" class="nom_fondo">' + entry['nombre'] + '</a>';
html += '<p class="text1"> CategorÃa :' +entry['categoria']+ '</p>';
html += '<p class="text1">' + entry['fecha_creacion']+ '</p>';
html += '</div>';
$('#content-middle').html(html);
});
html += '</div>';
}else{
$('#content-middle').html("<div id='wrapper-index'><p class='warning'> search delivered 0 results! </p></div>");
}
}
);
});
});
redirect and ajax request - El Forum - 04-19-2011
[eluser]Abdul Malik Ikhsan[/eluser]
i think, by jQuery, you can easyly remove div or append if needed
redirect and ajax request - El Forum - 04-19-2011
[eluser]toopay[/eluser]
If i'm not wrong, this is what you want to do
Code: <div id="header">
<?php $this->load->view('header'); ?>
</div>
<!--- CONTENIDO --->
<?php if (isset($contenido)) { ?>
<!---inicio contenido--->
<div id="content">
<div id="side-menu">
<?php echo $this->load->view('side_menu'); ?>
</div>
<div id="content-middle">
<?php if (isset($contenido2))
{
echo $this->load->view($contenido2);
}
else
{
echo $this->load->view($contenido);
}
?>
</div>
<div id="content-right">
<?php echo $this->load->view('mod_derecha');?>
</div>
</div>
<?php }else {
echo "<h2> No hay contenido visible </h2>";
} ?>
<!--- PIE DE PAGINA --->
<div id="footer">
<div class="center" >
<?php echo $this->load->view('footer'); ?>
</div>
</div>
redirect and ajax request - El Forum - 05-22-2011
[eluser]amipaxs[/eluser]
toopay, thanxs for your help, but it wasn't exactly what i wanted, you can browse a working sample now
http://www.phpchile.net/demo/portal/
then click on "Publicacion" ,
I did create a search_template ,
VIEW:
Code: <div id="side-menu">
<?php echo $this->load->view('side_menu'); ?>
</div>
<div id="content-middle">
</div>
<div id="content-right">
<?php echo $this->load->view('mod_derecha');?>
</div>
I get the search term through ajax and pass it to the controller, controller returns retrieved records, i load new search template in ajax and create neccesary divs , then load data on (#content-middle).load(html)
CONTROLLER:
Code: function buscar_ajax(){
$buscado = $this->input->post('busca');
$data['buscados']= $this->MFondos->buscarFondos($buscado);
$data = json_encode($data['buscados']);
echo $data;
}
function busqueda(){
echo $this->load->view('plantilla_busqueda');
}
Weirdly it seldom displays the searched data, for example "palace", also would like to receive some feedback about performance and loading time,
Thanks in advance
Rodrigo
|