Is a PHP variable supposed to be seen in a .js file included into a .php
file?
I have a client side javascript code stored in a .js file which is included
into a PHP file using
<script src="filename.j s></script>
This code initialises a Javascript variable
var u="string";
The string is supposed to be the value of $HTTP_HOST
So, when initialise this variable like
var u=<? echo $HTTP_HOST;?>;
I sterted getting a javascript message Syntax Error
Am I doing something wrong, or PHP variables are not seen in included js
files? 19 2244
aa wrote: Is a PHP variable supposed to be seen in a .js file included into a .php file?
I have a client side javascript code stored in a .js file which is included into a PHP file using <script src="filename.j s></script>
This code initialises a Javascript variable var u="string";
The string is supposed to be the value of $HTTP_HOST
So, when initialise this variable like
var u=<? echo $HTTP_HOST;?>;
I sterted getting a javascript message Syntax Error
Am I doing something wrong, or PHP variables are not seen in included js files?
js files are not parsed for PHP code unless you specifically tell the
webserver to do so. Therefore, "var u=<? echo $HTTP_HOST;?>;" in the .js
will error since the browser doesn't know what to do.
--
Justin Koivisto - sp**@koivi.com http://www.koivi.com
You need to modify your web server configuration so that .js files are
parsed by PHP.
For Apache, use something like the following:
AddType application/x-httpd-php .js
Kelvin
"aa" <aa@virgin.ne t> wrote in message
news:41******** *************** @ptn-nntp-reader01.plus.n et: Is a PHP variable supposed to be seen in a .js file included into a .php file?
I have a client side javascript code stored in a .js file which is included into a PHP file using <script src="filename.j s></script>
This code initialises a Javascript variable var u="string";
The string is supposed to be the value of $HTTP_HOST
So, when initialise this variable like
var u=<? echo $HTTP_HOST;?>;
I sterted getting a javascript message Syntax Error
Am I doing something wrong, or PHP variables are not seen in included js files?
---
Mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.grisoft.com).
Version: 6.0.773 / Virus Database: 520 - Release Date: 05/10/2004
Kelvin Mackay <no************ ********@remove .nospam.parts.g mail.com> wrote: You need to modify your web server configuration so that .js files are parsed by PHP. For Apache, use something like the following:
AddType application/x-httpd-php .js
Why not simply point the src to a php file, that way php isnt executed
for every other static js file. Just don't forget to set the correct
mimetype (application/x-javascript).
BTW TOFU is bad practice.
--
Daniel Tryba
At the extreme risk of going way off topic...
I believe that TOFU actually makes much more sense.
When you convince google-groups to preview the BOTTOM 30 lines of a
message, I'll switch over..
I find it hard to understand how anyone who uses a modern, message
threading news reader can tolerate bottom postings... I'm sure someone
will let me know.. :-)
R
Daniel Tryba <ne************ ****@canopus.nl > wrote in
news:ck******** **@news.tue.nl: Kelvin Mackay <no************ ********@remove .nospam.parts.g mail.com> wrote: You need to modify your web server configuration so that .js files are parsed by PHP. For Apache, use something like the following:
AddType application/x-httpd-php .js
Why not simply point the src to a php file, that way php isnt executed for every other static js file. Just don't forget to set the correct mimetype (application/x-javascript).
BTW TOFU is bad practice.
Ehtor wrote: At the extreme risk of going way off topic...
I believe that TOFU actually makes much more sense.
When you convince google-groups to preview the BOTTOM 30 lines of a message, I'll switch over..
The fact that some people don't know how to snip when using the correct
form of posting doesn't justify you using an incorrect form.
Brian
You're right, that would work better :-)
However, you could also put the directive in a .htaccess file in the
directory with the dynamic js files.
I personally prefer to give files their correct extensions so I don't
lose syntax highlighting (etc) in editors that don't allow you to
manually specify a file's type.
Forgive my ignorance, what does TOFU stand for?
--
Kelvin
"Daniel Tryba" <ne************ ****@canopus.nl > wrote in message
news:ck******** **@news.tue.nl: Kelvin Mackay <no************ ********@remove .nospam.parts.g mail.com> wrote:
You need to modify your web server configuration so that .js files are parsed by PHP. For Apache, use something like the following:
AddType application/x-httpd-php .js
Why not simply point the src to a php file, that way php isnt executed for every other static js file. Just don't forget to set the correct mimetype (application/x-javascript).
BTW TOFU is bad practice.
---
Mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.grisoft.com).
Version: 6.0.773 / Virus Database: 520 - Release Date: 05/10/2004
Ehtor <no****@nomail. com> wrote: At the extreme risk of going way off topic...
I believe that TOFU actually makes much more sense.
When you convince google-groups to preview the BOTTOM 30 lines of a message, I'll switch over..
30 lines under a full overquote is just as bad (at least), if you write
a posting you should take the time to make a readable posting, it should
be short and summarize for readability (just in case some messages don't
make it or get delivered out of order). TOFU or bottom posting are for
lazy people who write for themselves.
I find it hard to understand how anyone who uses a modern, message threading news reader can tolerate bottom postings... I'm sure someone will let me know.. :-)
So whats the reason for the full underquote? Modern threaded readers
make it easy for the user to get the full message if they want it to!
TOFU makes no sense in this case, so just don't resend the same old
article so people don't have to scan in just in case there is something
added.
--
Daniel Tryba
.oO(Ehtor) I find it hard to understand how anyone who uses a modern, message threading news reader can tolerate bottom postings...
Saves time, because you don't have to endlessly scroll down or look up
in another posting what the author is referring to.
I'm sure someone will let me know.. :-)
The usual (and for many people most readable) way is:
question
answer
question
answer
Like in any other discussion. Or do you wait until you got 5 questions
and then answer them all at once? If yes - how would you do this? Always
say something like "And now to your question about this and that"? Why
not simply answer/comment one question at a time?
Another thing that people writing top postings (BTW: what's TOFU in
English? I only know it in German ... *g*) seem to forget is the length
of the posting. With just adding an answer on top of another posting the
articles get longer and longer, hundreds of lines for just a handful of
new text. This wastes bandwidth and space on hundreds of newsservers.
Micha This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: nielson |
last post by:
I have a class which contains (1) a class variable and (2) a method
(e.g., methodA) which returns a reference to the class variable. If
the variable has been assigned a value by a constant initializer in
the "var" statement, my httpd process crashes with a segmentation
fault when I call methodA. If the variable is assigned a value in one
of the class methods, the httpd process does not crash when methodA is
called and the value returned...
|
by: Deane Barker |
last post by:
I have a function that selects a file to include, then includes is.
The file is including within the function, like so:
function include_file($file_name)
{
require $file_name;
return;
}
|
by: flemming eriksen |
last post by:
Dear NG.
IIS5 (and II6) , ASP 3.0.; W2k, WS03.
A websolution has a login-page, transaction page (just reading data), and
logout-page
Under heavy load I get in the IIS-Log : Too many variables (Microsoft OLE DB
privider for V.FoxPro: Too many Variables).
|
by: Dennis M. Straussfogel |
last post by:
I'm trying to implement a nested SSI file that has in it the line:
<!--#include virtual="<!--#echo var='VAR_location'-->pagelinks.txt" -->
where VAR_location is a variable set in the "calling" file. (I.e., the
original file sets VAR_location equal to a directory path, then #includes
the file in which the above line appears). I can #echo the variable
correctly from the included file, and typing the directory path explicitly
in this...
|
by: Rick Casey |
last post by:
Hello,
I am trying to get a trigger to fire when a record is deleted that will
record the deleted record in a history file. Here is the trigger code:
CREATE OR REPLACE FUNCTION logPedigreesDel() RETURNS TRIGGER AS '
begin
INSERT INTO PEDIGREES_hist(
PedigreeID,
| |
by: Arthur Dent |
last post by:
Hello all, sorry for the cross-post, but im not sure which group is best for
this question.
I am an ASP.NET developer, but am learning PHP/perl for the first time now
to make some to changes to a client's site which was done by someone else.
I wrote a debug TPL which ive got working great now and was Such a sense of
accomplishment!! :) . People always say how cryptic C can be, but i think
perl definitely beats C out! Anyway.... In the...
|
by: subramanian100in |
last post by:
I read in C++ Primer 4th Edition by Stanley Lippman, in page 57, that
const variables at global scope are local to a file by default.
What is the advantage of this rule ?
Suppose I have the following const variable defined in a.h
const int const_int = fn();
Suppose a.h is #included in a.cpp which also contains the following
|
by: whirlwindkevin |
last post by:
I saw a program source code in which a variable is defined in a header
file and that header file is included in 2 different C files.When i
compile and link the files no error is being thrown.How is this
possible.I thought it will throw "Variable redefinition Error". Giving
the source code for reference.Please help me out on this...
a.h
-----
int g;
void fun(void);
|
by: aki |
last post by:
Hi i want to use a variable , who value should retain within function
calls.
File 1
..........
static int flag=0
func1()
{
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |