Code Igniter:使用jQuery加载控制器,但禁止直接加载url(Code Igniter: Load controller with jQuery but forbid direct ur

编程入门 行业动态 更新时间:2024-10-25 08:25:30
Code Igniter:使用jQuery加载控制器,但禁止直接加载url(Code Igniter: Load controller with jQuery but forbid direct url loading)

我在Code Igniter中构建了一个网站,其中包含一个注释系统,可以为每个页面加载带有jQuery的控制器函数。

我还在加载时将文章ID作为URI段传递给控制器​​。

让我们说控制器名称是“注释”,功能是:

function get_comments(){ $article_id = $this->uri->segment(3); echo 'the uri segment is '.$article_id; }

我使用以下jQuery将它们调用到我的页面:

$(document).ready(function(){ $('.comments-holder').load('<?php echo base_url();?>comments/get_comments/'<?php echo $article_id;?>); });

这很好。

我想要完成的是禁止用户通过输入http://www.domain.com/comments/get_comments/加载“get_comment”函数

我相信有可能没有针对这个问题的解决方案,即使这意味着要做更多的更改,解决方法也会很好地工作。

I have a website build in Code Igniter with a commenting system that loads a controller function with jQuery for each page.

I'm also passing the article ID as URI segment to the controller while loading.

Lets say the controller name is "comments" and the function is:

function get_comments(){ $article_id = $this->uri->segment(3); echo 'the uri segment is '.$article_id; }

I call them to my page with the following jQuery:

$(document).ready(function(){ $('.comments-holder').load('<?php echo base_url();?>comments/get_comments/'<?php echo $article_id;?>); });

and this is fine.

The thing I want to accomplish is to forbid the user to load the "get_comment" function by typing the http://www.domain.com/comments/get_comments/

I believe that is possible not to have a solution for this problem a workaround will work good as well even if it means more changes to be done.

最满意答案

代码点火器默认具有此功能。

在ajax动作中添加:

if ($this->input->is_ajax_request()) { // your regular ajax code } else { // redirect or show error }

Code igniter has this by default.

Add this in the ajax action:

if ($this->input->is_ajax_request()) { // your regular ajax code } else { // redirect or show error }

更多推荐

本文发布于:2023-07-31 22:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1348587.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   控制器   jQuery   Igniter   Code

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!