Ajax获取父页面URI(代码点火器)

时间:2022-10-07 00:14:28

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:

我正在使用我正在处理的Code Igniter应用程序中的ajax动态加载内容,表单。但是,我需要为我的数据库插入获取URI段并在表单上自动填充日期框。通常人们会做以下事情:

$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.

但显然它只是尝试通过ajax请求而不是父级来读取被调用的文档的地址。

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

使用jquery和jquery ui包含在我的文档标题中。如果您需要更多信息,我正在使用jquery ui ajax标签:http://jqueryui.com/demos/tabs/#ajax

1 个解决方案

#1


1  

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

在执行Ajax请求时,您应该从父页面发送段。喜欢这个:

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>

#1


1  

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

在执行Ajax请求时,您应该从父页面发送段。喜欢这个:

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>