false, 'data'=>array()); // get post_id $post_id = isset($_REQUEST['post_id']) ? (int)$_REQUEST['post_id'] : false; // if found if (false !== $post_id) { // add your data to JSON repsonse, in this case the all post data $data['data'] = get_post($post_id, ARRAY_A); // change status to ok, just to make it easy to validate in your Javascript file $data['status'] = 'OK'; } echo json_encode($data); // Must exit here when call is done die(); } public function save_data() { // create a JSON array, default vales $data = array('status'=>false, 'data'=>array()); // get post_id $post_id = isset($_REQUEST['post_id']) ? (int)$_REQUEST['post_id'] : false; if (false !== $post_id) { // Save something // .... $data['status'] = 'SAVED'; } echo json_encode($data); // Must exit here when call is done die(); } } add_action('init', array('AJAX_Tutorial', 'init'));