我想從我的視圖發送數據到我的控制器使用AJAX。一旦完成,這個想法就是將這些數據轉發到一個新的視圖,然後用它來相應地顯示信息。但是,當我嘗試它時,數據無法到達視圖。奇怪的是,在使用Chrome的開發工具時,如果我在AJAX調用的成功函數中使用console_log數據,它會顯示變量是正確的,但是當我嘗試在html中顯示該變量時,它的值爲0.任何想法?AJAX發送不發送正確的值
我的看法功能:
$(document).on("keyup", function(e){
guess = String.fromCharCode(e.which).toLowerCase();
if (counter < test_key.length){
if (guess == 'f' || guess == 'j'){
if (guess == test_key[counter].answer){
console.log(counter);
console.log(test_key[counter]);
$(document).off('keyup');
$('#imageLocation').hide();
counter++;
practiceTask(counter, test_key, test_id);
}
else{
$.ajax({
type: "POST",
url: '<?php echo site_url('practiceTest/errorPage'); ?>',
data: {question: 6},
success: function(data){
console.log(data);
window.location.href = '<?php echo site_url('practiceTest/errorPage'); ?>';
}
});
}
}
}
});
我的控制器的errorPage功能:
function errorPage(){
if (!empty($_POST['question'])){
$data['question'] = $this->input->post('question');
}
else{
$data['question'] = 0;
}
$this->load->view("practice_incorrect_view", $data);
}
而我的新觀點practice_incorrect_view:
<html>
<head>
</head>
<body>
<?php echo $question; ?>
<div class="centered">
<div style="width: 500px; margin: 20px auto;">
</div>
</div>
</body>
</html>
你是PHP沒有返回任何可以輸出的東西。腳本接收輸入時調用'errorPage()'是什麼? –