我正在尝试处理服务器响应。我将此响应VIA ajax解析为我的控制器。从控制台,我得到POST getInternalRouteServerResponse
的结果,但是没有加载VIEW页面。有什么想法吗?
这是我的控制器:
public function getInternalRouteServerResponse()
{
$response = $this->input->post();
$html = $this->load->view("front/curse_interne.php", array(
'response' => $response
), true);
echo json_encode(array("status" => 1, "html" => $html));
}
这是我的观点(curse_interne.php):
<?php var_dump($response); exit();?>
我正确加载了我的观点吗? 提前谢谢!
更新:在这里添加了ajax代码:
$.ajax({ //hande the first response
url: MyVariable.urlsite + "curse_interne/searchInternalRoute",
type: "POST",
dataType: 'json',
data:
'&departure=' + $("#internal_origin_station option:selected").val()
+ '&arrival=' + $("#internal_destination_station option:selected").val()
+ '&date=' + $("#datepicker_plecare").val()
+ '&category=' + categories
+ '&clear_session=1',
beforeSend: function () {
$('html, body').animate({scrollTop: $('#right-content-mainwrapper').position().top}, 'slow');
$("#right-content-mainwrapper").html("<div style='font-size: 18px;margin-bottom: 25px;margin-top: 25px;text-align: center;'>Va rugam asteptati. Calculam rutele interne.</div> \n\
<div style='text-align:center;'><img src='" + base_url + "assets/images/loader-big.gif' style='display: inline-block;vertical-align: middle;margin-left:10px;'/></div>\n\
");
},
success: function (response) {
if (response.status == '1') {
$.ajax({ // here is the response that I want to show in view
url: MyVariable.urlsite + "curse_interne/getInternalRouteServerResponse",
type: "POST",
dataType: 'json',
data: response
})
} else {
$("#right-content-mainwrapper").html("<div id='right-content-mainwrapper'>\n\
<div id='comanda-bilet-maincontent'><div class='error'>" + response.message + "</div></div></div>");
}
}
})
答案 0 :(得分:0)
需要纠正你的第二个ajax电话。你错过了success
。并在成功后添加bellow line,如
$("#right-content-mainwrapper").html(data.html);
所以,
$.ajax({ // here is the response that I want to show in view
url: MyVariable.urlsite + "curse_interne/getInternalRouteServerResponse",
type: "POST",
dataType: 'json',
data: response,
success: function (data) {
//console.log(data.html);
$("#right-content-mainwrapper").html(data.html);
}
})