Welcome Guest, Not a member yet? Register   Sign In
redirect and ajax request
#1

[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
#2

[eluser]toopay[/eluser]
What template library you are using? I think this is a "design" stuff, not ajax problems.
#3

[eluser]amipaxs[/eluser]
hi,

I don't use a template library , I use my own template view

Code:
<div id="header">
      
      &lt;?php $this->load->view('header'); ?&gt;
      
    </div>
    
    &lt;!--- CONTENIDO ---&gt;  
    
    &lt;?php if (isset($contenido)) { ?&gt;
    &lt;!---inicio contenido---&gt;  
    <div id="content">
        <div id="side-menu">
          &lt;?php echo $this->load->view('side_menu'); ?&gt;
        </div>
            
        <div id="content-middle">
          &lt;?php echo $this->load->view($contenido); ?&gt;
        </div>
        
        <div id="content-right">
          &lt;?php echo $this->load->view('mod_derecha');?&gt;
        </div>
    </div>  
    &lt;!---fin contenido---&gt;  
    &lt;?php }else if (isset($contenido2)) { ?&gt;
    
    <div id="content">
        <div id="content-wide">
          &lt;?php echo $this->load->view($contenido2); ?&gt;  //use this to load the publish page
        </div>
    
    </div>
    &lt;?php }else {
      
        echo "<h2> No hay contenido visible </h2>";
    } ?&gt;
    
    &lt;!--- PIE DE PAGINA ---&gt;
    <div id="footer">
       <div class="center" >
         &lt;?php echo $this->load->view('footer'); ?&gt;
       </div>
    </div>
#4

[eluser]toopay[/eluser]
How your controller looks like?
#5

[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>");
            }        
                        }
            );
    
    });
  });
#6

[eluser]Abdul Malik Ikhsan[/eluser]
i think, by jQuery, you can easyly remove div or append if needed Smile
#7

[eluser]toopay[/eluser]
If i'm not wrong, this is what you want to do
Code:
<div id="header">
      
      &lt;?php $this->load->view('header'); ?&gt;
      
    </div>
    
    &lt;!--- CONTENIDO ---&gt;  
    
    &lt;?php if (isset($contenido)) { ?&gt;
    &lt;!---inicio contenido---&gt;  
    <div id="content">
        <div id="side-menu">
          &lt;?php echo $this->load->view('side_menu'); ?&gt;
        </div>
            
        <div id="content-middle">
          &lt;?php if (isset($contenido2))
                {  
                    echo $this->load->view($contenido2);  
                }
                else
                {
                    echo $this->load->view($contenido);
                }
         ?&gt;
        </div>
        
        <div id="content-right">
          &lt;?php echo $this->load->view('mod_derecha');?&gt;
        </div>
    </div>    
    &lt;?php }else {
      
        echo "<h2> No hay contenido visible </h2>";
    } ?&gt;
    
    &lt;!--- PIE DE PAGINA ---&gt;
    <div id="footer">
       <div class="center" >
         &lt;?php echo $this->load->view('footer'); ?&gt;
       </div>
    </div>
#8

[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">
          &lt;?php echo $this->load->view('side_menu'); ?&gt;
        </div>
            
        <div id="content-middle">
          
        </div>
        
        <div id="content-right">
          &lt;?php echo $this->load->view('mod_derecha');?&gt;
        </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




Theme © iAndrew 2016 - Forum software by © MyBB