summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--itjs.class17
1 files changed, 14 insertions, 3 deletions
diff --git a/itjs.class b/itjs.class
index 00da2d3..01b971e 100644
--- a/itjs.class
+++ b/itjs.class
@@ -21,7 +21,6 @@
class itjs
{
-static $charset;
/**
* Send HTTP headers (content-type) to transmit javascript code
@@ -31,13 +30,25 @@ static function send_headers($charset = null)
if (!$charset)
$charset = ini_get('default_charset') ?: 'iso-8859-1';
- self::$charset = $charset;
-
@header("Content-Type: application/x-javascript; charset=$charset");
@header('Expires: ' . gmdate('D, d M Y H:i:s', time()+10) . ' GMT'); # prevent broken data on IE reloads
}
/**
+ * Send HTTP headers (content-type) to send json
+ * $p['maxage'] Number of seconds the content is valid for without verification [30]
+ */
+static function json_headers($p = [])
+{
+ $p += ['charset' => ini_get('default_charset') ?: 'iso-8859-1', 'maxage' => 30];
+
+ @header("Content-Type: application/json; charset=" . $p['charset']);
+ if ($p['maxage'])
+ @header("Cache-Control: max-age=" . $p['maxage']);
+}
+
+
+/**
* json_encode the result with options suitable for using as javascript source code
* @param $values Array with values to be serialized
* @return String with javascript code to be sent to client