2013-06-18 27 views
0

我想在ajaxoptions的選項中捕獲javascript/PHP變量。例如;在ajaxoptions中捕獲變量yii

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)對象?

回答

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的(本)」像alert(JSON.stringify(jQuery(this))); - 你會得到數據的想法返回。