how to name a file properly

R

richard

I want to modify a javascript file so that some php script is included.
So that I can send some data to the database.
Using an externally linked file, which extension does the javascript file
now get?
JS or PHP?
 
L

Luuk

I want to modify a javascript file so that some php script is included.
So that I can send some data to the database.
Using an externally linked file, which extension does the javascript file
now get?
JS or PHP?

if it's a javascript file name it 'something.js'
if it's PHP name it 'something.php'
('something' can be something else... ;)

Mostly javascript is executed on the client. Therefore it should not
have the ability top update a database (which is normally at the
server-side).

I'm a little bit confused with your remark:
"I want to modify a javascript file so that some php script is included."

So, let me ask this question:
Can you give an example of what you want to do? (in code form)
 
D

Denis McMahon

Can you give an example of what you want to do? (in code form)

I suspect what he wants to do is set javascript variables from his php.

But this is guesswork.
 
R

richard

if it's a javascript file name it 'something.js'
if it's PHP name it 'something.php'
('something' can be something else... ;)

Mostly javascript is executed on the client. Therefore it should not
have the ability top update a database (which is normally at the
server-side).

I'm a little bit confused with your remark:
"I want to modify a javascript file so that some php script is included."

So, let me ask this question:
Can you give an example of what you want to do? (in code form)

Check out the javascript used by my site's player.
When a song is loaded and is actually playing, I need to send that data to
the database to update the records.
I'd post the code, but it's rather intense and I'm not sure which part
would be relevant to post.
 
B

Ben Bacarisse

Check out the javascript used by my site's player.
When a song is loaded and is actually playing, I need to send that data to
the database to update the records.

You need to read up on making HTTP requests from ECMAScript. You might
start here: http://en.wikipedia.org/wiki/XMLHttpRequest

Your description is a little odd, but it sounds as if you want the
client side script to do something on the server side, and that's done
with an HTTP request (it used to be call AJAX). Of course, it is
sometimes possible to get it done by simply clicking a button, either
directly of by script control.
 
L

Lewis

In message said:
I want to modify a javascript file so that some php script is included.
So that I can send some data to the database.
Using an externally linked file, which extension does the javascript file
now get?

That depends on how your server will handle the files and on exactly how
the files are used. For example, at least on apache, if you are
including the files in an html document, then the extensions don't
matter at all on the included files. This seems the most likely.
 
D

Denis McMahon

That depends on how your server will handle the files and on exactly how
the files are used. For example, at least on apache, if you are
including the files in an html document, then the extensions don't
matter at all on the included files. This seems the most likely.

It does matter if he wants to deliver javascript from a php file, as the
file will have to be .php for the webserver to hand it off to the php
preprocessor, but it seems that's not what he wants to do.
 
T

Tim Streater

Denis McMahon said:
It does matter if he wants to deliver javascript from a php file, as the
file will have to be .php for the webserver to hand it off to the php
preprocessor, but it seems that's not what he wants to do.

My impression, BICBW, is that he wants to "mix" some php into his js
that will somehow execute in the browser and that he can use to update
his database.

What he needs is to make an ajax request.
 
D

Denis McMahon

My impression, BICBW, is that he wants to "mix" some php into his js
that will somehow execute in the browser and that he can use to update
his database.
What he needs is to make an ajax request.

Yeah, I thought from the original post that he was trying to pass data
values from php to js, but in fact he's going in the other direction.

I'd just like to state here and now that for my own sanity, I have no
intention of even trying to help richard implement AJAX / XMLHttpRequest,
especially as after 10[1] years of building this website he obviously
still hasn't got the conceptual differences between get and post straight
in his head yet.

[1] Is it less? It seems longer.
 
B

Ben C

On 2013-11-03 said:
Check out the javascript used by my site's player. When a song is
loaded and is actually playing, I need to send that data to the
database to update the records.

It's not usually a good idea to send code directly from the browser to
the server where you just execute it.

It's not too hard for someone to send different code that then runs on
your server and does something malicious etc.

I would construct the return messages on the server, encrypt them there,
and embed them in the page. Then when someone plays the song, you send
back the message and decrypt it again on the server, throwing it away if
it doesn't decrypt to what you're expecting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top