'JSON', '#path' => 'json', ); } function json_server_server_error($message) { return array('error' => TRUE, 'message' => $message); } function json_server_server() { // JSON callback is used by jQuery to do crossdomain requests $json_callback = $_GET['jsoncallback']; $method = ''; $params = array(); // Check the request type and keep it's values if ($_GET['method'] != '') { $method = $_GET['method']; unset($_GET['q'], $_GET['method'], $_GET['jsoncallback'], $_GET['_']); $params = $_GET; } else { if ($_POST['method'] != '') { $method = $_POST['method']; unset($_POST['q'], $_POST['method']); $params = $_POST; } } // Find the service and process the service call foreach (services_get_all() as $service) { if ($service['#method'] == $method) { $args = array(); foreach($service['#args'] as $arg) { $args[] = $params[$arg['#name']]; } $result = services_method_call($service['#method'], $args); if (is_array($result) && $result['error']) { return _json_server_send(array('status' => FALSE, 'data' => $result['message']), $json_callback); } return _json_server_send(array('status' => TRUE, 'data' => $result), $json_callback); } } $error = services_error("Invalid method $method"); return _json_server_send($error, $json_callback); } /** * Return the correct JSON structure. * * This function converts data to JSON, obeying the callback information. * The Callback is required to bypass crossdomain check by the browser with the * jQuery getJSON support. */ function _json_server_send($data, $callback = '') { $data = drupal_to_js($data); if ($callback != '') $data = "$callback($data)"; return $data; }