Welcome Guest, Not a member yet? Register   Sign In
How to show something on the right from a link on the left using Ajax
#1

[eluser]the_unforgiven[/eluser]
Hi Guys,

Just wondering what's the best way to show something from a link

Basically I have a list of links on the left of my page and when a link is clicked I want the info to show on the right of the same page so you are never leaving the page you are currently on.

And this only needs to display when the link is clicked otherwise it will show some hmtl text i will place there.

Can someone point me in the right direction has to what is the best way to do this and I'm a noobie at Ajax so be gentle.
#2

[eluser]marjune[/eluser]
what i did in something like this is division for the menu and another division to where you show some stuff if the menu was clicked!!
#3

[eluser]the_unforgiven[/eluser]
What lines of code would i write in order to make the div appear once the link is clicked?
#4

[eluser]marjune[/eluser]
somethig like this

Code:
[removed]
  
$(function(){
  
   $('#menuone').click(function(){
      
      $('#display').load("<?php print base_url().'index.php/yourcontroller/controllerfunction'?>");

   });

});

[removed]

<a href = "#" id = "menuone">menu</a>


<div id = "display">


</div>
#5

[eluser]the_unforgiven[/eluser]
Ok great i'll try that then
#6

[eluser]the_unforgiven[/eluser]
That works but am using a foreach statement and its getting the id but it';s showing all data from DB

Code:
<div id="events" class="scroll-pane">

    &lt;?php
    $query = $this->db->query('SELECT * FROM mcd_events');

    foreach ($query->result() as $row)
    {
    
    ?&gt;
        <h3>Date:&lt;?php echo date("F j, Y",strtotime($row->created_on)) ?&gt;</h3>
        
        <p><br /><a >id ?&gt;" id="linkid">&lt;?php echo $row->title ?&gt;</a></p>
        
    &lt;?php } ?&gt;

</div>
</div>
&lt;!-- content left --&gt;

&lt;!-- content right --&gt;
<div id="content-right">
    
    <h2>Events/Rideouts</h2>
    
    <div id="display">
    &lt;?php
    $query = $this->db->query("SELECT * FROM mcd_events ");

    foreach ($query->result() as $row)
    {
    
    ?&gt;
        <p>&lt;?php echo $row->description ?&gt;</a></p>
        
    &lt;?php } ?&gt;
    </div>
    <div class="clear"></div>
</div>
#7

[eluser]marjune[/eluser]
your view in <div id="display"> </div> must in other file then your just calling it and load it in the <div id="content-right"></div>
#8

[eluser]the_unforgiven[/eluser]
Code:
<div id="display">
&lt;?php
    $query = $this->db->query("SELECT * FROM mcd_events ");

    foreach ($query->result() as $row)
    {
    
    ?&gt;
        <p>&lt;?php echo $row->description ?&gt;</a></p>
        
    &lt;?php } ?&gt;
    </div>

This is in the view folder, inside display div which is inside content-right div
#9

[eluser]marjune[/eluser]
and that must the other view file then just load it in the controller.
#10

[eluser]the_unforgiven[/eluser]
Sorry I dont understand that doesn't make sense




Theme © iAndrew 2016 - Forum software by © MyBB