Reputation: 363
I have a controller suppose a
and it has a function suppose index()
where i passed data from my view suppose b
using javascript like this:
var formURL = "<?php echo base_url();?>a/index/"+ $("#someid").val();
$.post(formURL).done(function(data){$("#something").html(data);
now i am receiving it in my controller like this:
public function index($somevalue= ""){
....
....
}
now after execution from the controller a
i am again passing array values to the view b
like this:
public function index($somevalue= ""){
....
....
$data['value1'] = $value1;
$data['value2'] = $value2;
$this->load->view('b', $data);
}
now when i am accessing the data in the view b
like this:
<?php if (isset($value1)) {
echo $value1;
}?>
i am not getting the value of value1
. what did i do wrong in this case???
Upvotes: 1
Views: 54
Reputation: 8168
It would be a lot lot better if you use AJAX
. This is what it precisely does.
AJAX request to controller i.e (sending datas to controller) Get the
AJAX
result i.e (sending datas back to views)
and from client side you can update it.
You can get the form values like
var formDatas = $('#form').serialize();
Then make an ajax request like
$.ajax({
type : 'POST',
url : 'url',
data : {formdata : formDatas },
success: function(result){
//update the view with the result
}
}
Upvotes: 1