Welcome Guest, Not a member yet? Register   Sign In
Problem with jquery AJAX and controller variable
#1

[eluser]condoace[/eluser]
I am trying to call a controller method from a jquery AJAX script, everything seems to work fine (i.e. when I check in Firebug the values/varaibles are being posted to the controller) however cant get any of the input variables using $this->input->post(). Check out my code below:

Any ideas would be helpful!?

VIEW

Code:
$(function() {  
  $("#submit").click(function() {  
        
      var name = $("input#name").val();  
      
   var email = $("input#email").val();  
  
   var company = $("input#company").val();  
  
   //alert (dataString);return false;  
   $.ajax({  
  type: "POST",  
  url: '<?php echo base_url().'index.php/launch/form';?>',  
  data: {'name' : name, 'email' : email, 'company' : company},  
  success: function() {  
    $('#contact_form').html("<div id='message'></div>");  
    $('#message').html("<h2>Contact Form Submitted!</h2>")  
    .append("<p>We will be in touch soon.</p>")  
    .hide()  
    .fadeIn(1500, function() {  
   $('#message').append("<img id='checkmark' src='images/check.png' />");  
    });  
  }  
   });  
   return false;          
        
        
  });  
});

CONTROLLER

Code:
function form() {
  
   $this->output->enable_profiler(true);
  
    $name = $this->input->post('name');
    
    $email = $this->input->post('email');
    
    $company = $this->input->post('company');
    
    $this->load->model('Model_launch');
    
     if($query = $this->Model_launch->enquiry($name,$email,$company))
     {
          
      $this->session->set_flashdata('result','test');
      
      $this->load->view('view_launch',$data);
      
      
     }
    
     else
     {  
    
      $this->load->view('view_launch');
      
     }  
    
  }
#2

[eluser]Make Code& Love Code[/eluser]
Hi !!!
I had check your code and tested also. Its working fine for me.I am including my code here. Just try it out again. Hope it will work.
VIEW FILE
=============

[removed][removed]
&lt;form action="&lt;?php echo base_url()?&gt;/index.php/welcome/checkform" method="post" name="frmPost"&gt;
<div id="contact_form">
</div>
<div id="message">
</div>
&lt;input type="text" id="name" name="name" /&gt;
&lt;input type="text" id="email" name="email" /&gt;
&lt;input type="text" id="company" name="company" /&gt;
&lt;input type="button" id="submit" value="Submit" /&gt;
&lt;/form&gt;
[removed]
Code:
$(function() {  
  $("#submit").click(function() {  
        // alert("dfsdfs");return false;
      var name = $("input#name").val();  
      
   var email = $("input#email").val();  
  
   var company = $("input#company").val();  
  
   //alert (dataString);return false;  
   $.ajax({  
  type: "POST",  
  url: '&lt;?php echo base_url().'index.php/welcome/checkform';?&gt;',  
  data: {'name' : name, 'email' : email, 'company' : company},  
  success: function() {  
    $('#contact_form').html("<div id='message'></div>");  
    $('#message').html("<h2>Contact Form Submitted!</h2>")  
    .append("<p>We will be in touch soon.</p>")  
    .hide()  
    .fadeIn(1500, function() {  
   $('#message').append("<img id='checkmark' src='images/check.png' />");  
    });  
  }  
   });  
   return false;          
        
        
  });  
});
[removed]


CONTROLLER
=================
Code:
public function index(){
    //$this->output->enable_profiler(true);
    $this->load->view('test');
}

function checkform() {

   echo $this->input->post("name");
   echo $this->input->post("email");
   echo $this->input->post("company");  
   exit;

}


Try this out. Hope your problem will solve. Its working fine for me. For your reference I have attached Screenshot with this post.

With Thanks & Regards,
Sanjay
Software Engineer,
Chennai,India
http://sanjoyinfoworld.blogspot.in




Theme © iAndrew 2016 - Forum software by © MyBB