javascript vs Java EE / PHP / other web development apps - javascript

I am wondering in what situations would it be better to use javascript instead of Java EE/PHP/others? Because before I only know javascript, then when I learned Java EE/PHP, I never use javascript anymore because I do everything in Java EE or PHP.
I hope you can enlighten me.

Javascript tends to be on the client (browser), even though some is starting to appear on the server side (node.js, for instance).
The others (PHP, Java EE, ASP.NET, JSP and more) are server side, mostly used for heavy processing, accessing databases etc... They generate HTML (and sometimes javascript) that is sent to the browser.

JavaScript and stuff like PHP is something completely different. JavaScript is clientside whereas PHP is sererside. Clientside code is executed by the site's viewer while serverside code is executed on the server and sends the results to the client. Serverside is also suited for accessing databases and other stored data.
You should use serverside code to generate your webpage to show the user, and clientside code such as JavaScript to give the users a more interactive experience.

Related

How to run PHP script actively on client side / client machine?

I'm trying to run a PHP script directly on the client side rather than taking request from a client to server & receiving back processed output or file. I created a PHP script which is running properly on the server side. I want to run that same PHP script on the client side as well. The PHP is not installed on the client side, it is only on the server side. Using <object> method I somehow managed to execute a PHP script on the client side. But it's just window or small frame that is visible on the current browser or in a page on the browser of a local machine (or client machine). So whenever PHP functions are invoked, it is executed at the server side, not on the client side.
Is there a way to execute PHP functions actually on the client side as well?
OR
Is there a way to open that entire working PHP page on the client side rather than on small window or in a frame of server page on a client browser without PHP installation?
What I tried is:
I created PHP script as "SERVER.php" which displays the name of all the files of a current working directory of the SERVER machine.
<?php
exec('dir', $status, $result);
var_dump($status);
?>
I want to get name of all the files of a current working directory but of CLIENT machine.
I created a html file as "CLIENT.html" that consists of the following code:
<object type="text/html" data="http://192.168.0.110:81/file2v2.php" width="800px" height="600px" style="overflow:auto;border:5px ridge blue">
</object>
Basically, the object function used in html contains the ip address followed by the port no. (of the Apache Server) and the php file name of the server (where php is installed and located).
Can anyone please help me how to execute PHP functions or say entire PHP scripts on the client side, or the way it can get it done.
All clients where you want to execute PHP scripts need to have PHP installed, as well as a running webserver (if those scripts are accessed via http). There is no way around that.
One way to do it without client side code is to give your webserver SSH access to all the clients. (This means creating the user on each machine and giving it the necessary permissions). Then the server could read the visitor's IP, connect to it via SSH and read the filesystem of the client and display it in the browser. This would be a wild approach, but possible.
Check this out: https://kvz.io/blog/2007/07/24/make-ssh-connections-with-php/
It would also mean that if someone gets access to that server or can somehow exploit it, all clients are compromised as well.
To run a script, you need an interpreter installed, the browser can read js script, but cannot read php script, for example.
https://en.wikipedia.org/wiki/PHP
I think you should take a look at the difference between client-side and server-side. Take a look here, it explains a lot.
Quote from the above link:
Key Differences Between Server-side Scripting and Client-side Scripting
Server-side scripting is used at the backend, where the source code is not viewable or hidden at the client side (browser). On the other hand, client-side scripting is used at the front end which users can see from the browser.
When a server-side script is processed it communicates to the server. As against, client-side scripting does not need any server interaction.
The client-side scripting language involves languages such as HTML, CSS and JavaScript. In contrast, programming languages such as PHP, ASP.net, Ruby, ColdFusion, Python, C#, Java, C++, etc.
Server-side scripting is useful in customizing the web pages and implement the dynamic changes in the websites. Conversely, the client-side script can effectively minimize the load to the server.
Server-side scripting is more secure than client-side scripting as the server side scripts are usually hidden from the client end, while a client-side script is visible to the users.
If you want every logic done on the client-side, take a look at Angular, VueJS or just basic Javascript. But with Javascript (including Angular/VueJS/Etc.) you can not manipulate client-side files, which would be a major security issue if it was able to. To change things on the server-side, you will always need a back-end programming language like PHP, C#, Java etc.
Be aware that everything you do on the client-side, is visible for the client and can be changed by the client. Which makes your application vulnerable for attackers.
To answer your question: You can't.
Basically, no.
But you can read about C# Blazor approach (https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor) and try to implement something like this.

Can AJAX and JavaScript be used purely for server side scripting?

I am just learning php. My approach to learning is that I start analysing the code in a language I am more familiar with.
Hence, I am trying to replicate a PHP dashboard with PHP features like role management, session logging etc.
As I am halfway through it, I find that using ajax , though not primarily meant for it, I can talk to a server.
Using Http verbs, I can also make modifications.
Hence, can JavaScript and Ajax together act as a server side scripting language on its own?
My understanding is a server side scripting language just interacts with the server.
As ajax does the same using JavaScript and http verbs .
Can it essentially replace PHP?
I did a little research, and found server side scripting languages have their own pros like filtering, jQuery and Ajax can use less bandwidth etc.
But everything seems vauge.
Hoping to get a better understanding.
Thank you:)
Server side scripts run at the server, not at the "client" (browser). Javascript run at the browser. Ajax is a feature of JS that allow you to interact with a server without doing a full POST back to that server (changing the page you are actually seeing). During an AJAX call you can interact with whatever is on the server side (PHP, .NET, etc) There are even some sites that have multiple server side scripts.

Client side scripting and Server side scripting languages

What scripting languages comes under client side and what and all comes under server side?
If JavaScript is scripting language, then what about jquery. jquery is nothing but javascript library rite? so jquery is client side scripting?
I goggled it, but its still confusing. In some sites its given, client side scripting are JavaScript and vb script and in some other sites its saying only JavaScript. In case of server side, they are mentioning html also.
Can i have a clear idea about this.
Client Side:
Scripts that execute in client side. In context of websites, it is scripts that execute in the browser of the user.
Eg: Javascript, VB etc.
(JQuery, DOJO are libraries build on top of Javascript so it is also client side.)
Server Side:
Scripts that execute in the Server. In context of website, it is scripts that execute on application servers.
Eg: PHP, Python, Ruby etc
We cannot classify languages as client side or server side. There could be a scenario where a server can execute Javascript and render HTML from it. In this context Javascript becomes a server side lanuage. I hope I did not confuse you.
What scripting languages comes under client side
For all practical purposes: JavaScript
and what and all comes under server side?
Every programming language under the sun (including JavaScript)
If JavaScript is scripting language, then what about jquery. jquery is nothing but javascript library rite? so jquery is client side scripting?
It is a library. Yes. Generally … it is geared very heavily towards the browser, but (in theory at least) you could use it with something like PhantomJS for manipulating webpages on the server.
I goggled it, but its still confusing. In some sites its given, client side scripting are JavaScript and vb script and in some other sites its saying only JavaScript. In case of server side, they are mentioning html also.
Internet Explorer (although prossibly only older versions) also supports VBScript for client side programming. Using it isn't practical on the WWW since it doesn't run anywhere else.
Quoted with minor formatting changes from user61852's answer
"Here I will talk only about web programming.
Client side programming has mostly to do with the user interface, with which the user interacts. In web developing it's the browser, in the user's machine, that runs this code, and is mainly done in javascript, flash, etc. This code must run in a variety of browsers.
Its main tasks are:
validating input
animation
manipulating UI elements
applying styles
some calculations are done when you don't want the page to refresh so often
The person in charge of front end programming must know:
javascript
css
HTML
basic graphic design
Ajax
maybe Flash
some 3rd party javascript libraries like JQuery
UI design
information design, etc.
Server side programming has to do with generating dynamic content. It runs on servers. Many of these servers are "headless". Most web pages are not static, they search a database in order to show the user updated personalized information. This sides interacts with the back end, like say, the database.
This programming can be done in a lot of languages:
PHP
Java and jsp
asp
Perl
Python
Ruby on Rails, etc.
This code has to do which:
Querying the database
Encode the data into html
Insert and update information onto the database
Business rules and calculations
The person in charge of server side programing must know:
some of the languages mentioned above
HTML
SQL,
linux/unix shell scripting
OOP
business rules, etc."
If the code is compiled/run on the clients machine, it is considered client-side. Serverside means a script which is compiled/run on the server before sending it to a browser. jQuery is just a library for JavaScript. That's all clientside.
For instance, some common used languages on the web.
Client-side: JavaScript
Server-side: PHP, Ruby, Perl
In Client side scripting,Script file usually download on client system and client browser compiled this script file and generate HTML. And Generated HTML display by browser.
EX- JavaScript file, Jquery file, AngularJs file.
In server side scripting, when user request page for display then script run on server and generate dynamic HTMl file and send this HTML file to user.
EX- Asp(.asp), Asp.Net(.aspx), PHP(*.php).
Please go through the below link
for client side programming and server side programming
https://softwareengineering.stackexchange.com/questions/171203/what-are-the-difference-between-server-side-and-client-side-programming
As for client side scripting and server side scripting. I think if you go through all the answers for this question you will get a clear idea.
jQuery is a framework that uses JavaScript internally.
Javascript isn't just a client-side scripting language. It is extensively used for it. But it ain't its only use. Its just the way we use Javascript to implement our functionality. Its a misconception that Javascript is used only for client-side scripting.

Write to server: using text file with HTML5 Jquery/Javascript

I was wondering if it is possible to write to a server and storing it in a text file using Javascript/Jquery, HTML5. The purpose is, I am making a javascript/jquery game and I wanted to store the scores, without using any server-side language (php, asp, etc.)
Thank you so much for the help, your time is much appreciated.
HTML, JS, CSS, all that is client-side. Meaning it runs in the browser and that's that.
PHP & ASP are server-side, meaning the code gets executed on the server and the result gets sent to the client.
You need a method of communication between the client and server. You can send requests using JS (AJAX) but you'll need something on the server to receive and do something with them. For that you need some server-side code.
So no, you can't update data on a server using only client-side technologies. You can, however, use client-side scripts to communicate with a server and tell the server-side code to update data.

cXML PunchOut Transaction and Javascript

I am researching how to PunchOut enable a webstore and from what I read, I have to use a server side language. Unfortunatly I am limited to only using Javascript. Can this be done? Does anyone have any best practices or can point me to a reference for enabling a PunchOut ecommerce store by only using Javascript?
According to the cXML Users Guide (http://xml.cxml.org/current/cXMLUsersGuide.pdf) on page 23 it states "PunchOut catalogs are made possible by Web server
applications, written in a programming language such as ASP (Active Server Pages),
JavaScript, or CGI (Common Gateway Interface), that manage buyers’ PunchOut
sessions.". Based on that it sounds possible as they call out JavaScript, but they also call out the fact that it is done by Web server applications. I have not used a strictly JavaScript myself, just ASP and recently .NET.
However, I'm not a JavaScript expert so YMMV. The main thing to keep in mind that most punch-outs (especially from Ariba) will be initiated via an HTTP POST with the cXML document XML as a form value. If you can use JavaScript to process that XML and send back a response without server side work, then you should be good to go.

Categories

Resources