duansang8388 2013-06-18 18:07
浏览 46
已采纳

在ajaxoptions中捕获变量yii

I want to capture javascript/PHP variable in the ajaxoptions' options. 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"
                    )
            );

In the success option I have two alerts to show you guyz how do i want it. Which doesn't display correct data. Is there any way to get the php variables and the jQuery(this) object?

  • 写回答

1条回答 默认 最新

  • duanbi5906 2013-06-18 18:49
    关注

    I have extracted the data i wanted from "jQuery(this)". Actually "jQuery(this)" returned me the data in a different format. Below is the code.

       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"
                            )
                    );
    

    if alert the "jQuery(this)" like alert(JSON.stringify(jQuery(this))); - you will get the idea of the data returned.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 全志v3s怎么设置高速时钟,使用的荔枝派zero开发板,串口2需要921600的波特率
  • ¥15 关于#单片机#的问题:Lora通讯模块hc-14电路图求内部原理图
  • ¥50 esp32 wroom 32e 芯片解锁
  • ¥15 bywave配置文件写入失败
  • ¥20 基于Simulink的ZPW2000轨道电路仿真
  • ¥15 pycharm找不到在环境装好的opencv-python
  • ¥15 在不同的执行界面调用同一个页面
  • ¥20 基于51单片机的数字频率计
  • ¥50 M3T长焦相机如何标定以及正射影像拼接问题
  • ¥15 keepalived的虚拟VIP地址 ping -s 发包测试,只能通过1472字节以下的数据包(相关搜索:静态路由)