User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,574 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,828 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 460 | Replies: 11
Reply
Join Date: Nov 2006
Location: South Wales
Posts: 159
Reputation: phper is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
phper's Avatar
phper phper is offline Offline
Junior Poster

Re: Echoing PHP variables in JavaScript

  #11  
33 Days Ago
What if the user disabled Javascript?
If you find my post useful please add to my reputation!! Thanks!

ajtrichards web solutions
http://www.ajtrichards.co.uk
Reply With Quote  
Join Date: Sep 2005
Posts: 639
Reputation: digital-ether has a spectacular aura about digital-ether has a spectacular aura about 
Rep Power: 5
Solved Threads: 38
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Re: Echoing PHP variables in JavaScript

  #12  
32 Days Ago
Originally Posted by adaykin View Post
Javascript will execute the code. Just try putting an alert, where the header type is
Header("content-type: application/x-javascript"); you will see :-)


That is interesting...
I've created an example here: http://de-test1.appjet.net/
But it doesn't execute for the browsers I tested.

It does not seem to me that a JS resource should be executed on its own, but meant to be executed in the context of another application, such as a HTML Document on a browser, XUL document in Firefox, as Actionscript in Flash etc. etc.

Originally Posted by adaykin View Post
Like I said before a header WOULD NOT WORK since I have to pull information from a database first. You MUST put a header at the top of the page.


The HTTP Response Header just needs to go before the HTTP Response body, it does not matter where in the PHP script it is issued...
You can use output buffering if you need. http://www.php.net/ob_start

eg: for a redirect:

// at the top of your page start the HTTP buffer
ob_start();

// heres your HTML
echo '<p>I am a paragraph</p>';

// then you decide to redirect, clear the buffer
ob_end_clean();
// issue the change in location. 
header('Location: http://example.com/');
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Other Threads in the PHP Forum

All times are GMT -4. The time now is 10:29 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC