I have this view where I collect a key named MYVAR in a form contactForm
<form class="form-wrapper cf" id="contactForm">
<input name="MYVAR" type="text" placeholder="DO_IT..." required>
<button type="submit" id="btn_submit" > DO IT </button>
</form>
then in this view I have a script to send via ajax this key to controller as dataString
<script type="text/javascript">
jQuery(function() {
jQuery(".btn_submit").click(function() {
var MYVAR = jQuery("input#MYVAR").val();
var dataString = 'MYVAR='+ MYVAR;
alert(dataString);
jQuery.ajax({
type: "POST",
url: "<?php echo base_url()?>index.php/do_it/method/",
data: dataString,
success: function() {
jQuery('#successMessage').html("<b><p style='color:#5b5b5b; float:left; margin-top:3px; padding-top:50px;'>success.</p></b><br/><br/>")
.hide()
.fadeIn(1500, function() {
jQuery('#successMessage');
});
}
});
return false;
});
});
</script>
In the controller do_it inside method i would read var MYVAR
function method()
{
//posted var
$key = $this->input->post('MYVAR');
$this->load->model('mine_model');
//get data according key variable
$data['result'] = $this->mine_model->get( array('data' => $MYVAR));
//encode it?
echo json_encode($data);
//$this->load->view('view',$data);
}
But Is not doing anything...
What am I missing?
Also I do not have any idea How to receive $data ['result'] in view with jQuery and then print it in view?