ajax - CodeIgniter - Nothing is shown in the view -


i don’t know problem is. have ajax sends username controller:

function my_profile(username){      $.ajax({         url: "member/my_profile",        type: "get",        data: "username="+username,        success: function(){            window.location.href = 'member/my_profile';        }     }); }  

and controller:

function my_profile(){       $username = $this->input->get('username');     $data['username'] = $username;     $this->load->view('my_profile' , $data); }  

i have echo $username test can alert(msg) ajax. works find. problem nothing shown in view:

    <h1>my profile</h1>  <?php  echo $username; ?>  

i don’t know why. tried initialized $data['username'] = 'adam' , works.

the problem window.location.href = 'member/my_profile';. redirect profile page without username value.

you want do:

 window.location.href = 'member/my_profile?username='+username; 

though, still don't understand why have ajax call there. couldn't do:

function my_profile(username){      window.location.href = 'member/my_profile?username='+username; } 

your ajax call loading page discarding contents, don't think need here.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -