使用ajax调用无法获得正确的路由

时间:2014-03-06 17:25:00

标签: php jquery ajax yii

我无法通过ajax调用获得正确的路线

在我看来,我有2个用PHP创建的html按钮

<?php if ($comment_exist == null): ?>    
   <p><input type ="button" id = "sb" value="I Comment"></p>
<?php else: ?>              
   <p><input type ="button" id = "sb2" value="I Cancel my Comment"></p>
<?php endif ?>

我的jquery脚本包含以下内容

<script>
   $(document).ready(function(){                     
      $(function(){
         $("#sb").click(function(e){
            $.ajax({
               type: "POST",
               url: "comment/create",
               success: function(data) {
                  $("#message_ajax").html("<div class='successMessage'>" + data.message +"</div>");
           }
           });
        });
      });
    });
</script>

我收到了以下地址

localhost/mysite/index.php/post/comment/create

而不是

localhost/mysite/index.php/comment/create

我必须说我的视图我的按钮是由后置控制器启动的 我想调用注释控制器的创建视图。我正在使用Yii框架

提前感谢您的帮助

1 个答案:

答案 0 :(得分:1)

我以下列方式成立

我用这个

替换url行
url: "<?php echo Yii::app()->createUrl('comment/create'); ?>"

感谢您的帮助。

但我现在有另一个问题,我会发布另一个问题

相关问题