Concrete5 5.7 form block type ajax
PermalinkHow to enable ajax for form block type?
For sending form without page reload.

* For use in a block you probably have to prefix 'action_' before the response function.
function updateCatActive(id, active) { $.ajax({ dataType: "json", type: "post", data: { pk: id, name: 'Active', value: active }, url: "<?php echo $view->action('update_cat_field')?>", success: function(response) { console.log(response); } }); }
controller:
public function update_cat_field() { $ret = array('success' => false, 'message' => t("Error")); if ($this->isPost()) { $catID = $this->post('pk'); $catField = trim($this->post('name')); $catValue = trim($this->post('value')); if (($catID > 0) && is_string($catField) ){ $ret['success'] = true; // do some magic } else $ret['message'] = t('Error' . $catID . $catField . $catValue); } else $ret['message'] = t('Error, no parameters'); echo Core::make('helper/json')->encode($ret); exit; }
Don't forget the exit.