dongsimang4036 2012-09-21 07:38 采纳率: 100%
浏览 47
已采纳

奇怪的锚标签行为

In my view im doing this :

<?php if($user_can_write) {?>
<a href=<?php echo base_url('backend_controllers/users/foo')?> style="text-decoration:none">
Add</a>
<?php } ?>

I pass variable $user_can_write from my controller , which is my implementation for access control, the strange part is whenever i refresh this page , ie this view , the anchor tag is executed , ie , the foo function in user controller is called and executed , every time !Basically the foo function increments the db by one row (adds row to the db), so this is really not practical for me that on every refresh the anchor tag executes

Now if i do this implementation in the view (alternate approach) :

<?php if($user_can_write) {?>
<a href='javascript:void(0);' onclick="on_click_method_for_anchor()" style="text-decoration:none">
Add</a>
<?php } ?>

and further in my javascript i do this :

function on_click_method_for_anchor(){
$.ajax({
            url: '<?php echo base_url('backend_controllers/user/foo'); ?>',            
            type: 'POST',
            success: function(result){                
                $('.my_span_tag_class').html(result)
            }
        });

this seems to work perfect , and even if i reload the page , the foo is not called , can someone please tell me why is the anchor tag behaving like this ? am i missing out something obvious ?

  • 写回答

1条回答 默认 最新

  • duandai2178 2012-09-24 12:13
    关注

    I think you miss the " " part just after href properties of anchor tag.

    <?php if($user_can_write) {?>
    <a href="<?php echo base_url('backend_controllers/users/foo')?>" style="text-decoration:none">
    Add</a>
    <?php } ?>
    

    Try this. I think it will be ok

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程