onunix 2012-08-14 13:34:20 2709次浏览 4条回复 0 0 0

admin文件中增加如下代码,但是,好像这种定义函数的方法和调用方法,有点问题,该如何定义onclick中可以调用的函数呢

function  abcd()
{
}
// the link that may open the dialog
echo CHtml::link('点我吧','#',array(
   'onclick'=>[color=Blue]'abcd();[/color]$("#mydialog").dialog("open"); return false;',
));
  • 回复于 2012-08-14 13:50 举报

    我知道 'onclick'=>'abcd();$("#mydialog").dialog("open"); return false;',
    这是在客户端执行的,不可能调用服务器端的代码的,但是我确实有这种需求,就是在客户端的
    http://localhost/yii/Yii/index.php?r=Test/admin 的页面上,用户点击一个按钮,然后不关闭这个页面(http://localhost/yii/Yii/index.php?r=Test/admin)的前提下,执行一些服务器的代码,这该怎么做呢? 我上面一个帖子是一种示意。

  • 回复于 2012-08-14 14:54 举报

    我写成这样子了:

    在admin.php中加入

    <script type=”text/javascript”>
    function ajaxupdate()
    {
    //url=”<?php echo Yii::app()->request->baseUrl;?>/index.php/site/”+url;
    var pars = "";
    $.ajax({
    type: “POST”,//以POST方法接收表单数据
    url: “http://localhost/Yii/index.php?r=test/index”,
    data: pars,
    dataType : “php”,
    success: function(msg){
    }
    </script>
    
    <?php 
    echo CHtml::link('点我吧','#',array(
       'onclick'=>'alert("点击了我"); ajaxupdate();alert("点击了我"); return false;',
    ));
    ?>
    

    但还有点错误,谁能够帮我改改,使得 http://localhost/Yii/index.php?r=test/index 得到执行吗?

  • 回复于 2012-08-14 16:18 举报

    得到执行了,代码如下:

    <?php 
    echo CHtml::ajaxLink('GO', 'http://localhost/Yii/index.php?r=test/export',  
    array('type'=>'POST'), //there are various other options for jquery ajax  
    array('href'=>'http://localhost/Yii/index.php?r=test/export')); 
    

    但是怎么得到控制器中actionexport()的返回值呢(return的值)

  • 回复于 2012-08-14 17:57 举报

    使用ajax调取。

您需要登录后才可以回复。登录 | 立即注册