views:

53

answers:

1

Hello,

I'm loading content, forms mainly, dynamically using ajax in a Code Igniter app I'm working on. However I need get the URI segments for my DB insert and to autofill the date box on the form. Usually one would do something along the lines of:

$date = $this->uri->segment(3)."/".$this->uri->segment(4)."/".$this->uri->segment(5);

But obviously it just tries to read the address of the document being called through the ajax request, not the parent.

Any ideas how I get the parent details?

Thanks!

<meta charset="UTF-8" />

<script type="text/javascript">
    $(function() {
        $("#tabs").tabs({
            ajaxOptions: {
                error: function(xhr, status, index, anchor) {
                    $(anchor.hash).html("Unable to load this tab. We'll try to fix this as soon as possible.");
                }
            }
        });
    });
</script>

<div id="diary-input">

<div id="tabs">
    <ul>
        <li><a href="<?php echo base_url()."index.php/diary_add_appt" ?>">Appointment</a></li>
        <li><a href="<?php echo base_url()."index.php/diary_add_event" ?>">Event</a></li>
        <li><a href="<?php echo base_url()."index.php/diary_add_client" ?>">New Client</a></li>
        <li><a href="<?php echo base_url()."index.php/diary_add_contact" ?>">New Contact</a></li>
        <div id="input-cell-close" class="input-cell"><a href="#"><?php echo "<img src=\"".base_url()."images/cc_close.png\" id=\"input-cell-close\" border=\"0\" alt=\"close\" />" ?></a></div>
    </ul>
</div>

</div>

With jquery and jquery ui included in my document header. I'm using the jquery ui ajax tabs if you need further info: http://jqueryui.com/demos/tabs/#ajax

+1  A: 

When doing the Ajax request, you should send along the segments from the parent page. Like this:

In your controller:

$data['segments'] = $this->uri->segment(3)."/".$this->uri->segment(4)."/".$this->uri->segment(5);

In your view:

<li><a href="<?php echo base_url()."index.php/diary_add_appt/{$segments}" ?>">Appointment</a></li>
<li><a href="<?php echo base_url()."index.php/diary_add_event/{$segments}" ?>">Event</a></li>
<li><a href="<?php echo base_url()."index.php/diary_add_client/{$segments}" ?>">New Client</a></li>
<li><a href="<?php echo base_url()."index.php/diary_add_contact/{$segments}" ?>">New Contact</a></li>
captaintokyo
Thanks for your reply Captiain Tokyo! I've added some further info above, let me know if you need anything else.
Robimp
Hello, you still there?
Robimp
Sorry not sure how jQuery Ajax tabs work... can also post the html for the tabs? Thanks.
captaintokyo
Yeah sure, just updated my post...
Robimp
I updated my answer with some code? Do you get the idea? Does this work for you?
captaintokyo
Hi Captain Tokyo, sorry I completely missed this, think I forgot to select the notifications. Thanks for the code update, that makes sense now, thanks! +1!
Robimp