Re: Feature Request: Script data headers

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