W3C home > Mailing lists > Public > public-html-comments@w3.org > April 2013

Re: Feature Request: Script data headers

From: Arthur Clifford <art@artspad.net>
Date: Mon, 22 Apr 2013 23:25:56 -0700
Message-Id: <79ABA2B3-9512-4EB5-A58A-22BAC5E32393@artspad.net>
To: "public-html-comments@w3.org" <public-html-comments@w3.org>
If you are using php then you would do:
<?php
	$responseData = array();
	$responseData['name']='bob';
	$responseData['people'] = array('larry','moe',curly');
?>
<script type='text/javascript'>
	var responseData = "<?php echo json_encode($responseData) ?>";
</script>

Which would give you more the kind of data structure you were looking for.

Having said that, a <data> tag might be useful. It would need an id, type and optional src attribute. 

The only real advantage over the script tag would be if javascript or other scripts treated data tags as variables.  so:
<data id='message' type='text/plain'>Hello World</data>
<script type="text/javascript">
	alert(message);
</script>

would alert "Hello World".


Art C

On Apr 22, 2013, at 3:49 PM, C Havemann <thecmann1@gmail.com> wrote:

> Currently if you want to send data from the server to the client side script you have output a script tag, for example in PHP:
> <?php
>     $data = 'value';
> ?>
> <script type="text/javascript">
>     var data = <?php echo data ; ?>;
> </script>
> Which works but somehow doesn't seem right to me.
> I would imagine something that works like POST data except in reverse.
> The data is sent back in the response headers and the browser would process the data to return it in nice usable format
> Maybe it could be accessed in javascript something like this:
>  var name = responseData['name'];
> var person1 = responseData['people'][0];
> 
> var person2 = responseData['people'][2];
> 
Received on Tuesday, 23 April 2013 06:52:10 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:26:29 UTC