#1
  1. Superhero
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    OH
    Posts
    27
    Rep Power
    0

    Accessing PHP with JavaScript?


    I want to allow users to imbed some JavaScript code on their site that will access a php page on my site and display the results of the php code back on their site.

    What I think I need to do is create a PHP page that will put the database query into an object on page load and use JavaScript to access that object and display the results on the user's web site.

    I can't seem to come up with the right search terms to find an example/tutorial on this so I think I'm overlooking alternate ways of handling it...

    Any suggestions on a method/language that will make this work?

    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    108
    Rep Power
    11
    The Facts:

    PHP - Server side
    JavaScript - Client Side

    The only thing these to languages have in common, and the only way they can 'communicate' would be if you had PHP or JavaScript create a cookie, and then have the other access it. This looks like the way for you to go about this. BUT, some people don't accept cookies, so this won;t work for them.

    The best thing for you ro do would be to include a file from your server, from your friend's site/server.
  4. #3
  5. Superhero
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    OH
    Posts
    27
    Rep Power
    0
    Thanks for the reply...

    That clarifies my question - what is the best way/is there a way to interface a client side language with a server side one?

    If I had a php page that only ran one function (from an included file) and the function created an html table from a database query - could I transfer that html text string to the requesting JavaScript for display on the other web site?

    Something like what is done on weather.com where a JavaScript accesses their site and displays weather info for a specific zip code - I'm assuming getting the data from weather.com's database...

    Can that be done with PHP/JavaScript or should I look for another language?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Posts
    790
    Rep Power
    15
    Seems like you guys are complicating this a bit. It sounds like your wanting these other sites to have some function that opens a page on your site and displays the results on their site.

    Why not just have a link ( or javascript if you just have to have it) that opens the page from your server in a frame or iframe on their site?
  8. #5
  9. Superhero
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    OH
    Posts
    27
    Rep Power
    0
    I just stumbled across iframes - looks like this may do the trick...

    Thanks!
  10. #6
  11. Superhero
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    OH
    Posts
    27
    Rep Power
    0
    Just in case anyone else is interested in the solution to my problem, this article explains how to use PHP to create JavaScript code that can then be dynamically linked to another web site...

    http://www.devarticles.com/art/1/53/3
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    5
    Rep Power
    0
    There are two other ways to have PHP give values to Javascript. You could have PHP create a Javascript array containing the values desired and just have your js script grab that array. You could also use DOM to grab values from the html, which could have been generated by the PHP

IMN logo majestic logo threadwatch logo seochat tools logo