|
Posted by Morlaath on 08/27/07 18:03
On Aug 27, 12:55 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Morla...@gmail.com wrote:
> > On Aug 27, 7:33 am, Jeff North <jnort...@yahoo.com.au> wrote:
> >> On Mon, 27 Aug 2007 02:00:11 -0000, in comp.lang.php
> >> Morla...@gmail.com
>
> >> <1188180011.507936.75...@r34g2000hsd.googlegroups.com> wrote:
> >>> | Is there a way to embed php within javascript code? I know that php is
> >>> | server side and js is client side. For instance when working with jsp,
> >>> | you can imbed jsp scriptlets within the js code.
> >>> |
> >>> | e.g
> >>> |
> >>> | <script language="javascript">
> >>> | function foo() {
> >>> | var bar = <%=(java variable)%>
> >>> |
> >>> | <% if (bar == null) { %>
> >>> | alert("Null value");
> >>> | <% } %>
> >>> | }
> >>> | </script>
> >> <script type="text/javascript">
> >> function foo() {
> >> var bar = <?php echo variable;?>
>
> >> if(bar == null) {
> >> alert("Null value");
> >> }}
>
> >> </script>
> >> -- -------------------------------------------------------------
> >> jnort...@yourpantsyahoo.com.au : Remove your pants to reply
> >> -- -------------------------------------------------------------
>
> > Anytime I embed php within javascript with the <?php ?> tags the php
> > executes as soon as the page is loaded. So for instance if I have
> > something like the following.
>
> > //Javascripts
> > function foo() {
> > <?php session_destroy(); ?>
> > }
>
> > <input type="button" value="logout" onclick="foo();"/>
>
> > The 'session_destyoy()" is called as soon as the page is loaded,
> > instead of when you click on the button.
>
> That's right. PHP is server side, not client side. It will always be
> executed before (or as) the page is sent to the browser. There is no
> way to call a PHP function from javascript directly.
>
> The only way you could do it is with something like AJAX, which would
> make a call to the server to perform the action.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================
I was hoping it would work something like jsp, which I deal with all
day at work. You can embed jsp scriptlets within js code and it will
not be executed until the the js function is called. Jsp is also
server side ;P
Navigation:
[Reply to this message]
|