I have a simple ajax request in my view page that i want to bind to an action in my controller :
function updateDates(id,val){
$.ajax({
type: "POST",
url: "<?=APPLICATION_URL_ADMIN?>campaign/changedate",
data: ({id:id,duree:val}),
cache: false,
error: function(msg){
alert('Il y a eu une erreur.');
},
success: function(){
console.log('ok');
window.location.href=window.location.href;
}
});
}
and in my controller :
public function changedateAction()
{
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('changedate', 'html')->initContext();
global $mySession;
$db = new Db();
$data = $this->_request->getPost();
$data_update['campaign_length'] = $data['duree'];
$data_update['launch_date'] = date("Y-m-d H:i:s");
$condition = "campaign_id='" . $data['id'] . "' ";
$db->modify(LAUNCHCAMPAIGN, $data_update, $condition);
}
Here's the request string rendered in the chrome console, which is fine : http://www.mydomain.ndd/admin/campaign/changedate?id=4&duree=45
It's throwing an error 500 and i don't know why. Can anyone help me ?
Edit:
I changed my action in the controller, but my db is still not updated
public function changedateAction()
{
global $mySession;
$db = new Db();
if ($this->getRequest()->isXmlHttpRequest()) {
// makes disable renderer
$this->_helper->viewRenderer->setNoRender();
//makes disable layout
$this->_helper->getHelper('layout')->disableLayout();
if ($this->getRequest()->isPost()){
$data = $this->_request->getPost();
$data_update['campaign_length'] = $data['duree'];
$data_update['launch_date'] = date("Y-m-d H:i:s");
$condition = "campaign_id='" . $data['id'] . "' ";
$db->modify(LAUNCHCAMPAIGN, $data_update, $condition);
$this->view->text = $data['duree'];.' processed';
}
}
}
Can somebody help me ? i'am stuck.
Thanks