2017-09-28 1 views
0

나는 codeigniter를 사용하고 있습니다. 내 프런트 엔드 코드에서이 일을하고있다 : - PHP 응답에서 오는 HTML을 렌더링하는 방법

$scope.book=function(){ 
$http.get("./Booking/index") //getting response as an html page, should render it to do correctly. 
    .then(function (data) { 
     console.log(data);  //prints whole html code of booking.html 
}); 
} 

그리고 내 예약 컨트롤러

내가 뭐하는 거지 : -

public function index(){ 
    $this->load->view('booking'); 
} 

그래서 나는 HTML 페이지 getting response as html page

등의 응답으로 무엇입니까

html을 프론트 엔드 코드로 렌더링하고 싶습니다. 어떻게 할 수 있습니까? 간단한 말로하면 나는 내 책의 기능을 원할 때, 내가 요청한 응답으로 프론트 엔드로 예약 페이지를 포기한다. 내 대답에, 그래서

답변

2

로 JQuery와 변화에 컨트롤러 변경해야 벌거 벗은 자바 스크립트. 해결책은 페이지의 요소 내용을 대체하는 것입니다. 그렇게 할 수 있습니다

$scope.book=function(){ 
$http.get("./Booking/index") 
    .then(function (data) { 
     document.querySelector('.class_selector_or_#id_or_body').innerHTML = data;  
}); 
} 
-3

당신은, 당신이

public function index(){ 
    print_r($this->load->view('booking', '', TRUE)); 
} 

처럼 내가 당신이 사용하고있는 JS 프레임 워크 모르는이

$scope.book=function(){ 
$http.get("./Booking/index") //getting response as an html page, should render it to do correctly. 
    .then(function (data) { 
     console.log('success'); 
     $("#some_div_id"),html(data); 
}); 
} 
+2

OP는 확실히 'print_r()'을 사용하여 html을 파괴하고 싶지 않습니다. 그리고 OP가 jQuery를 사용하고 있는지 확실하지 않습니다. Angular와 비슷합니다. – jeroen

+0

참조 오류 : html이 정의되어 있지 않습니다. 종속성으로 추가했지만 인젝터 모듈 오류가 발생했습니다. – Asim

+0

@AsimRaja는'$ ("# some_div_id")를 사용합니다 .html (data)'는 기본 jQuery입니다. – anwerj

관련 문제