doujiao7483 2011-09-19 23:09 采纳率: 0%
浏览 73
已采纳

来自View的Yii Controller调用?

I have a view that has a form. I have a button which calls a controller via Ajax.

    echo CHtml::submitButton('Generate', array(
        'ajax'        => array(
            'type'    => 'POST',
            'url'     => CController::createUrl('Calculator/generateRetailers'),
            'update'  => '#div_retailers'
        )
    ));

The action controller what it does is to gather some data from MySQL and then renderPartial HTML tables into my form. Exactly in the div #div_retailers. This is the create option. Now I am trying to implement the update action which should render the information provided in the create action and draw the tables.

I would like to be able to call generateRetailers action controller from my view. Something like this:

<div id="div_retailers">
</div>

<script type="text/javascript">
    // I would like to call a url using jQuery?
    $.ajax({
        url: "/Calculator/generateRetailers"
    });
</script>

How can I achieve this?

Thanks

  • 写回答

2条回答 默认 最新

  • doulizhi1247 2011-09-20 08:26
    关注

    Do the exact same thing you already do in the widget:

    <script type="text/javascript">
      // I would like to call a url using jQuery?
      $.ajax({
        url: "<?php echo CController::createUrl('Calculator/generateRetailers');?>"
      });
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架