1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

call php from javascript

Discussion in 'JavaScript' started by nikolaaa, Nov 7, 2006.

  1. #1
    I have some string output in php and want to call it from java:
    <script language="JavaScript" type="text/javascript" src="http://mysite/myphp.php"></script> 
    Code (markup):
    or maybe with
    <script language="JavaScript" type="text/javascript">
    document.open('http://mysite/myphp.php')
    </script> 
    Code (markup):
    so users can use it in html files.

    how to make output in php and how call it from html...
    i realy dont know java..
     
    nikolaaa, Nov 7, 2006 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    You cannot include php pages in HTML like that. There are serval ways.

    1. iFrames (eww)
    2. Add HTML to the list of extensions that php will parse and put your code there.
    3. Change the .html extension to .php and put your code there.
    4. You can call the content with AJAX and place it in your HTML document. (Not google friendly)

    The best method would be either method 2 or 3. You can do that with htaccess for example.

    
    AddType x-httpd-php .php .htm .htm
    
    Code (markup):

    EDIT:

    You can also include files with SHTML
    
    <!--#include FILE="filename.php"-->
    
    Code (markup):
    Don't rely on Javascript cause not all users have it enabled.
     
    nico_swd, Nov 7, 2006 IP
  3. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #3
    my preferred way:

    <script language="JavaScript" type="text/javascript">
      dummyimage = new Image();
      dummyimage.src = http:www.yourdomain.com/yourfile.php
    </script>
    Code (markup):
    you create a dummy image and cheat javascript to think that the source of the image is a php file - the code in the php file gets called well and good! ;)
     
    daboss, Nov 7, 2006 IP
  4. smallbuzz

    smallbuzz Peon

    Messages:
    125
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    by the way, java and javascript are not the same thing.
     
    smallbuzz, Nov 8, 2006 IP