在ajaxoptions中捕获变量yii

时间:2013-06-18 18:07:00

标签: php yii

我想在ajaxoptions中捕获javascript / PHP变量'选项。 e.g;

CHtml::ajaxLink("My link", Yii::app()->createUrl('controller/definition'), array(
                'data' => array("id" => $model->id),
                'type' => 'POST',
                'error' => 'js:function(data){}',
                'beforeSend' => 'js:function(request){}',
                'success' => 'js:function(data){
                         alert(jQuery(this).attr("id"));
                         alert({$model->id});
                 }',
                'complete' => 'js:function(data){}',
                    //'update'=>'#where_to_put_the_response',
                    ), array(
                "confirm" => "Are you sure you want to delete?",
                        "id" => "linkID",
                        "href" => "javascript:;",
                        "title" => "mTitle"
                    )
            );

在成功选项中,我有两个警告,告诉你guyz我想要它。哪个没有显示正确的数据。有没有办法获取php变量和jQuery(this)对象?

1 个答案:

答案 0 :(得分:0)

我从“jQuery(this)”中提取了我想要的数据。实际上“jQuery(this)”以不同的格式返回了数据。以下是代码。

   CHtml::ajaxLink("My link", Yii::app()->createUrl('controller/definition'), array(
                    'data' => array("id" => $model->id),
                    'type' => 'POST',
                    'error' => 'js:function(data){}',
                    'beforeSend' => 'js:function(request){
                          mdata=(jQuery(this)[0]["data"]).replace( /^\D+/g, "");
                     }',
                    'success' => 'js:function(data){
                             alert(mdata);
                     }',
                    'complete' => 'js:function(data){alert(mdata);}',
                        //'update'=>'#where_to_put_the_response',
                        ), array(
                    "confirm" => "Are you sure you want to delete?",
                            "id" => "linkID",
                            "href" => "javascript:;",
                            "title" => "mTitle"
                        )
                );

如果警告“jQuery(this)”,如alert(JSON.stringify(jQuery(this))); - 您将了解返回的数据。