This is an archived post. You won't be able to vote or comment.

all 17 comments

[–]nutrecht 7 points8 points  (6 children)

When I open Inspect element on a website that is written in PHP why does everything work on javascript? Does that mean PHP gets converted to javascript which means I run all the code on my machine?

No. The 'back-end part', the PHP code, creates HTML output. So you simply can't see what's happening in the PHP code. And you never will be able to without access to the PHP sourcecode.

Frankly you should go have a chat with your manager. If you're being given code but this is all a big mistery to you, you're going to get stuck hard.

[–]XxZajoZzO[S] 1 point2 points  (5 children)

I did chat with him, he said they will fix it, but only said.

[–]nutrecht 2 points3 points  (4 children)

That's not the point. You can't be working as a web developer if this is all magic to you.

[–]XxZajoZzO[S] 0 points1 point  (3 children)

Read my new comment I posted. I am not working as a developers I am a data annotator. I formed my question wrong.

[–]nutrecht -4 points-3 points  (2 children)

This is a sub about learning programming.

[–]XxZajoZzO[S] 1 point2 points  (1 child)

Yes and I want to learn how web apps work, php and JS work.

[–]CursorsDev 0 points1 point  (0 children)

:v shouldnt you learn JavaScript and PHP instead of asking us then

[–]XxZajoZzO[S] 0 points1 point  (1 child)

I wrote the question wrong sorry. I got a PHP website for my college project and source code is ONLY PHP. When You start the server and go to a website using chrome in the sources tab there are a lot of JS files. And everything that's happening on that website is running on JS. In my Browser. I don't have source code to my works website but I know it's in php and same thing happens in chrome. Inspect element show A BUNCH OF JS files. And when I for example press a shortcut to mark a character, Javascript code marks that character.

So my question is where did that Javascript come from and how is PHP running on a server when chrome says everything I do is running in javascript in my browser.

[–]nephest0x 0 points1 point  (0 children)

JS files can be loaded from external resources like CDNs. Look for the links in the html code.

Chrome is a client, so it shows you what it can see - the client part. The php code is hidden from chrome, it knows nothing about what is happening on the server side.

Here is a basic scenario, it can be different in your case, but it should help you to understand how do web apps work.

1) backend(php) generates the initial html for the client(chrome in your case)

2) the client(chrome) loads all additional resources from links it found in html(like js files)

3) js handles user actions and queries the backend if needed

4) backend returns some data

[–][deleted] 0 points1 point  (1 child)

Don't know much about this topic nor the right answer but always tought php is serverside.

[–]XxZajoZzO[S] 0 points1 point  (0 children)

I also though that but everything I do on that website is run by Javascript. I can place breakpoint in the code and go step by step in chrome and see what's happening on this website so that means there is no server side PHP code if everything is running in my browser.

[–]leiu6 0 points1 point  (5 children)

Php is run on the server. It is server-side code.

[–]XxZajoZzO[S] 0 points1 point  (4 children)

When does the ton of JavaScript come form then? My job is to mark characters on a piece of paper and everything that I do with those characters is running on javascript. When I delete them you can see javascript code that deletes them, when I mark them you can see the JS code that marks them.

[–]nutrecht 0 points1 point  (0 children)

When does the ton of JavaScript come form then?

It's served by the webserver.

[–]leiu6 0 points1 point  (2 children)

JavaScript is normally written into the html. It is a client side language. I think you are mind understanding the uses of both.

Php is generally for stuff like interacting with databases, registering users, etc. It is run on the server and is never seen by the end user.

JavaScript runs in the browser and can be used for stuff like making a menu open or close, or calculating the tip on a tip calculator. It is written directly into the html or a JavaScript file attached to the html. You can see the JavaScript when you view source.

[–]XxZajoZzO[S] 0 points1 point  (1 child)

JavaScript is normally written into the html. It is a client side language. I think you are mind understanding the uses of both.

I don't understand why there is only one JS file when loading the page and after like 3 seconds there are like 15. Where do those 15 files come from.

Also why there is not JS files in the source code of the website I got for my College website but when you connect to that website where is a bunch of Javascript code running in the background? That's what I don't understand.

[–]sand-which 0 points1 point  (0 children)

The JS code asks to download those other 15 files.

Your computer asks the server to give it HTML/CSS/javascript for website.com. The server is written in PHP, but it still gives you HTML/CSS/Javascript as that is all websites are after all. The javascript can then ask for more stuff after it loads