如何呈现来自 php 响应的 html

How to render html which is coming from php response

我正在使用 codeigniter。 我在我的前端代码中这样做:-

$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 页面

我想将 html 呈现为前端代码,我该怎么做?简而言之,我希望我的书在执行时能发挥作用,放弃预订页面作为前端,我从 get 请求中得到响应。

你需要像这样改变你的控制器

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

并在您的jquery中更改为

$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);
 });
}

我不知道你用的是哪个js框架,所以我的回答是空的javascript。解决方案是替换页面中元素的内容。你可以这样做

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