Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中使用ajax方法时需要获取当前页面URL_Php_Jquery_Ajax_Codeigniter - Fatal编程技术网

在php中使用ajax方法时需要获取当前页面URL

在php中使用ajax方法时需要获取当前页面URL,php,jquery,ajax,codeigniter,Php,Jquery,Ajax,Codeigniter,我需要获取当前页面的URL 实际上,我在Codeigniter框架中单击当前页面中的链接时使用了弹出框 在这里,我使用ajax响应方法在弹出框中显示了一些内容。 在该内容中,我将其编码为 $this->uri->segment(2) 。 这里我只得到了ajax方法中给出的url,但我需要得到我持有弹出框的页面的url。在Codeigniter中: 要获取完整的URL,请执行以下操作: 通过使用current\u url()方法,可以获取页面的当前页面url 例如: $page_url=curre

我需要获取当前页面的URL

实际上,我在Codeigniter框架中单击当前页面中的链接时使用了弹出框 在这里,我使用ajax响应方法在弹出框中显示了一些内容。 在该内容中,我将其编码为

$this->uri->segment(2)


这里我只得到了ajax方法中给出的url,但我需要得到我持有弹出框的页面的url。

在Codeigniter中:

要获取完整的URL,请执行以下操作:

通过使用
current\u url()
方法,可以获取页面的当前页面url

例如:

$page_url=current_url();
echo $page_url;
URL:   **http://example.com/project_name/login/home**

echo $this->uri->segment(1); //It will returns login as output
echo $this->uri->segment(2); //It will returns home as output
要获取URI段,请执行以下操作:

通过使用以下语句,可以获得URI中的段

语法:

$this->uri->segment(n);
       where n=1 for controller
                 n=2 for method
                 n=3,4,5,6........ for parameters.
例如:

$page_url=current_url();
echo $page_url;
URL:   **http://example.com/project_name/login/home**

echo $this->uri->segment(1); //It will returns login as output
echo $this->uri->segment(2); //It will returns home as output
要获取当前控制器和方法名称,请执行以下操作:

$this->router->fetch_class(); //It will returns controller name
$this->router->fetch_method(); //It will return current method name.
在jQuery中:
您可以使用jQuery获取当前页面url,如:

var pathname = window.location.pathname;

在codeigniter中,您可以使用URI类获取当前URI段

$currentUrl = base_url().$this->uri->uri_string();
在这种情况下,您需要在配置文件中设置基本url并加载url帮助程序以使用
base\u url()
函数。

获取当前页面url: 例如:


您需要查看引用方以获取弹出窗口的url(而不是目标AJAX url)。这可以使用UserAgent类(
$This->agent->referer()
)完成


请参见

这是在jQuery中,但我需要在phpjust short way base_url(uri_string())中获取它;