SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need to print php code through javascript

    Hi

    I need to call a php code through javascript as I want it to be hosted on one server and run from another server. What I have is this:

    <?Header("content-type: application/x-javascript");
    $random_number = rand();
    echo "document.write(".$random_number.")";
    ?>

    This code gives me a perfect output, but now I want to stylize it i.e this code should be wrapped in div and perhaps an enitre page of its own. The problem is now I need to write the entire page in this fashion and that is exactly the thing that is not working. For eg. if I try to write
    echo "document.write("<div id="header"")"; it gets executed but does not get printed i.e. I don't get any output on the page. Please help.

    Thanks

  2. #2
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I needed to do something like that a looong time ago and I think I found out that you can't.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Thanks for the reply, but isn't there a way I can stylize the content, otherwise it makes no meaning to just show the output code. There must be some way.

    Thanks

  4. #4
    SitePoint Addict
    Join Date
    Jul 2009
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have you tried escaping your quotes?

    PHP Code:
    echo "document.write('<div id=\"header\">')"

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Thanks for the reply. Actually the problem is I have
    echo "document.write(".$random_number.")";
    to print the random number which it shows up correctly. But if I add another echo statement, even a simple hi or hello word to be printed, the page is blank i.e. I don't get any output even if I can see the code in if I do inspect element in firefox.

    thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •