Welcome Guest, Not a member yet? Register   Sign In
how to access the data i posted through ajax on my controller
#1


Code:
$.ajax({
                    type: "POST",
                    url: '<?php echo site_url('login/identifying_usertype'); ?>',
                    data: { 'email' : email, 'password' : password },
                    success: function(response){
                        
                        //console.log(response);
                        //alert(email);
                        console.log(response);
                        $('#myModal').modal('hide');
                        },
                        error: function (XHR, status, error){
                            console.log('error', error);
                        }
                    });

and this is my controller
Code:
public function identifying_usertype()
{
    $email = $_POST['email'];

     echo "$email";
}
I can't get the posted value on my ajax Is there something I'm missing? what could be wrong?
Reply
#2

Maybe $this->input->post('name');
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(08-16-2017, 09:15 AM)InsiteFX Wrote: Maybe $this->input->post('name');

A little background on this question ... it comes from a stack overflow question that I was trying to help Lestah with. If he posts to the Welcome controller, then $this->input->post('name') works, but if he posts to any other controller then $this->input->post('name') returns NULL. It's very bizarre. Have you heard of such a thing?
Reply
#4

(This post was last modified: 08-16-2017, 11:37 AM by InsiteFX.)

Nope, the only thing I can think of is maybe he needs to clean his web browsers cache out.

If he specify's the correct controller then it should post to it.

Ahhh, look at his ajax url, he is only using single qoutes

Code:
// should be like this.
url: "<?php echo site_url('login/identifying_usertype'); ?>",

Not sure if that's the problem but it should be like I showed.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(08-16-2017, 11:31 AM)InsiteFX Wrote: Nope, the only thing I can think of is maybe he needs to clean his web browsers cache out.

If he specify's the correct controller then it should post to it.

Ahhh, look at his ajax url, he is only using single qoutes

Code:
// should be like this.
url: "<?php echo site_url('login/identifying_usertype'); ?>",

Not sure if that's the problem but it should be like I showed.

We spent a lot of time trying to figure this out yesterday. Didn't suggest cleaning the browser cache, but jumped through a lot of hoops:

https://stackoverflow.com/questions/4570...9_45705168
Reply
#6

(This post was last modified: 08-16-2017, 06:42 PM by ciadvantage.)

Would you check your form if the email input with 'attribute' name='email' and  password input name='password'?

Code:
<form>
  <p>Email:<input type='text' name='email' />
</p>
<p><input type='password' name='password' /></p>
<input type='submit' value='Submit' />
</form>
<script>
   var data=$('form').serialize();
   var url = 'your_url'; // ie. login/identifying_usertype
    $('form').on('submit',function(e){
              e.preventDefault();
  
   $.post(url,data,function(response){
     
     },'json').done(function(response){
         console.log(JSON.stringify(response));// should have response data here
     }).fail(function(){
         //some action as you please
     });//end post
     });//end submit
</script>
 
  then in the controller:
  
Code:
public function identifying_usertype()

 $data=$this->input->post(NULL,TRUE);

 echo json_encode($data); //should response as json string at view
}

 Try that code and see if  you see the response.  I m pretty sure you should!
 Good luck
Reply




Theme © iAndrew 2016 - Forum software by © MyBB