2017-12-29 53 views

답변

0

당신은 원하는 컨트롤러에 Ajax 요청을 보내고 Json으로 데이터를 반환하여 javasscript로 읽을 수 있습니다.

$.ajax({ 
    type: 'GET', 
    url : '/site/countor?id='+pathArray[2], 
    crossDomain: true, 
    success: function(output) { 


     alert(output); 

    }, 

    contentType:'application/json; charset=utf-8', 
    dataType: 'json' 

});}} 

siteController 카운터 조치 : :

여기

는 샘플 파일 (당신이 어떤의 .js 파일에 넣어 레이아웃 또는 jsRegister 기능에서 바인딩 할 수 있습니다)

test.js입니다

public function actionCountor($id) { 
       $p1 = new View(); 
       $p1->ip = Yii::$app->request->getUserIP(); 
       $p1->post_id = $id; 
       if ($p1->save()) { 
        $arr = array('id'=>$p1->id; 
        return json_encode($arr); 
       } 
}