1

I am working on a project using PHP Codeigniter. I want to know how can I sent a variable with JQuery to the controller. Below is my code

<script>
 function Reset_User_Password(id){

  $.post("<?=base_url();?>WebAdmin/Reset_User_Password/id", {id: id}, function(page_response)
  {
  $(".modal-body").html(page_response);
  });

 }
</script>

Here I'm first getting the variable 'id' from function parameter. But when I run this code, it return the string 'id' instead of the actual user id from database. I want to view the user id. Below is my function from the controller..

public function Reset_User_Password()
{
$data['admin_id'] = $this->uri->segment(3);

$this->load->view('admin/user/reset_user_password', $data);
}
0

4 Answers 4

2

Send data by POST method is not append in url as GET method. So you can't get is using $this->uri->segment().

Instead use

$data['admin_id']=$this->input->post('id');
Sign up to request clarification or add additional context in comments.

Comments

2

Use

$this->input->post('id');

Don't use $this->uri->segment(3); because you are posting id by post method if you want to use $this->uri->segment(3); then do a minior miodification in your function

     $.post("<?=base_url();?>WebAdmin/Reset_User_Password/"+id, function(page_response)
      {
      $(".modal-body").html(page_response);
   });

Comments

1

You can take help with this code. It is working perfectly at my end

function Reset_User_Password(){

    var currentpwd= document.getElementById("currentpwd").value;

    var newpwd = document.getElementById("newpwd").value;

    var cnfrmnewpwd = document.getElementById("cnfrmnewpwd").value;

    var url = "<?php echo base_url('user/changepwd'); ?>"

    $.ajax({

        type:"POST",

        data:{currentpwd:currentpwd,newpwd:newpwd,cnfrmnewpwd:cnfrmnewpwd},

        url:url,

        success:function(data){ 

             if(data){

             $('#newsleter').html(data); 

             }
        }   

    }); 

}

Comments

1

try below code you should get that id variable from GET method on the controller.

function Reset_User_Password(id){
  $.post("<?=base_url();?>WebAdmin/Reset_User_Password/id="+id
  $(".modal-body").html(page_response);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.