Hello all,

I need to serve Javascript as the output of one action, instead of
regurlar HTML. The purpose is that i want to be able to call this
action from other pages outsite cake (in another domain) like so:

<script src="http://mysite/controller/action";
type="text/javascript"></script>

So the output of my action (a bunch of document.write()'s with HTML) is
rendered in the page that called it.

I can do this with a regular PHP file by sending a javascript header
and then echo'ing the javascript, like:

<?php
header("Content-type: application/x-javascript" );
echo "document.write(\"<div id='mi_sabrosus'>\");\n";
...
echo "document.write(\"</div>\");\n";
?>

So, to use this strategy in Cake I created a new layout with:

<?php
header("Content-type: application/x-javascript" );
echo $content_for_layout;
?>

And set the action to use this layout via $this->layout. Then the view
does all the echo'ing of the javascript.

But this is not working. If I browse to
http://mysite/controller/action, the output I see is exactly the same
as if I browse to the regular PHP file in http://mysite/file.php.
However, trying to include the code in another page with <script> tags
doesn't work for the cake version, only for the normal PHP version.

I tried putting the header and the echo's directly in the controller
too, setting $this->autoRender to false, but that didn't work either.

I'm out of ideas now... If anyone could help me on this I'd very
apreciated.
Thanks,
Rodrigo.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to