php - AJAX Post not sending the correct values -


i trying send data view controller using ajax. once done, idea forward data new view, use display information accordingly. however, when try it, data not reach view. weird, in using chrome's developer tools, if console_log data in success function of ajax call, shows variable being correct, when try display variable in html, has value of 0. ideas?

my view function:

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

my controller errorpage function:

function errorpage(){     if (!empty($_post['question'])){         $data['question'] = $this->input->post('question');     }     else{          $data['question'] = 0;     }     $this->load->view("practice_incorrect_view", $data); }  

and new view practice_incorrect_view:

<html>   <head>   </head>    <body>          <?php echo $question; ?>        <div class="centered">        <div style="width: 500px; margin: 20px auto;">        </div>      </div>   </body> </html> 

the root of problem posting practicetest/errorpage (hence correct console), in success callback, navigating practicetest/errorpage doesn't know form data posted.

$.ajax({     type: "post",     url: '<?php echo site_url('practicetest/errorpage'); ?>',     data: {question: 6},     success: function(data){         console.log(data);         //-- troublesome line         //-- window.location.href = '<?php echo site_url('practicetest/errorpage'); ?>';     }  });  

you should modifying dom directly using data returned successful ajax request instead of redirecting using window.location.

is there example somewhere?


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -