开发者

Yii Controller call from a View?

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


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>


Interesting, there is no built-in url generator for ajax. So im calling ajax with helper variable, which is generated by my yii app. I use Yii::app()->clientScript("config.url = ".Yii::app()->createUrl() . "); and then in pure javascript i can use a global variable config where i have generated urls.

$.ajax({
url: config.url
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜