I think it is simple.
I have a Codeigniter function that takes input from a form and inserts it into the database. I want the Ajaxify process. At the moment, the first line of the function receives the id field from the form - I need to change this to get the id field from the Ajax message (which refers to a hidden field in the form containing the desired value). How should I do it?
My Codeigniter Controller Function
function add()
{
$product = $this->products_model->get($this->input->post('id'));
$insert = array(
'id' => $this->input->post('id'),
'qty' => 1,
'price' => $product->price,
'size' => $product->size,
'name' => $product->name
);
$this->cart->insert($insert);
redirect('home');
}
And jQuery Ajax Function
$("#form").submit(function(){
var dataString = $("input#id")
$.ajax({
type: "POST",
url: "/home/add",
data: dataString,
success: function() {
}
});
return false;
});
As always, thank you very much in advance.
source
share