Is it possible to execute Javascript on server side and to get the result on a client ?
If it is possible, how can i make the request to the dedicated Javascript file from my client ?
In fact, i have created a mobile application with embeeded Javascript, (using Phonegap) but i would like to put all Javascript files on the server and make some requests to the server to get the result.
Thanks for your help
See You have to create a Web Service on the Server Side to enable the Client(Phonegap App) to make an Ajax request and fetch some data.
Earlier you could have written a web service using programming languages like PHP, .NET, Java, Ruby, Python etc. But NodeJS provides the flexibility of writing REST Based web services in Javascript itself.
You can learn about it here: http://appsonmob.com/nodejs-expressjs-mysql/
Related
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.
I need to create a web page that gets data from an SQL database, and can run certain executables (that have already been written from previous projects).The code to retrieve data from SQL was written in C#, as it was used previously with ASP.NET. Is it possible to reuse all of this code the way it is with my current application (using Angular)?
How to set up the server side? I know I probably have to create a web server, and then use "get" and "post" requests from the client side, am I on the right track. Can JavaScript client side communicate with a C#-written server side?
Unequivocally yes, you can have a JavaScript frontend communicate with a C# backend. There are two primary MS provided technologies that can be used:
ASP.NET WebAPI
SignalR
And lots of 3rd party ones (like Nancy).
WebAPI is a simple HTTP server typically used to build RESTful backends. Given your description its probably what you want to use.
SignalR is a protocol for "push" applications (though it can be used for server invocations). If you don't need to call client-side code its a bit overkill.
On the client side, if using WebAPI or similar on the backend, you just do HTTP requests as you would against any standard API. For AngularJS that's done with the $http service, for Angular (2+) that's Http and for 4+ HttpClient.
I need some help on solving the following:Write a JS to invoke a Java method which in turn calls a database. Host the application on tomcat. Use mysql as the database.
I wrote down a sample code in java and accessed a sample database from MySql, now- How can I access this from a JS.
My assumption here is that you are talking about client side java script and not server side java script. You are trying to implement a standard client-server use case. Here your java script code is client and your java code is server. Since your client side code will be running inside a browser most likely so your best best will be to expose your java method invokable over http protocol. For this you will need to host your Java application as a web-application using servers like Tomcat, JBoss etc. You can search about how to implement this on Google.
You can begin with following links:
http://helloworldprograms.blogspot.com/2010/08/servlet-hello-world.html
http://crunchify.com/create-and-deploy-simple-web-service-and-web-service-client-in-eclipse/
I'm working on a Parse web app and have run into some problems using the backbone.js based client side javascript sdk. I noticed the way I have things set up, the client can view all of my source code by simply using the dev tools to view source files and can also run code against the database (within the limits of the ACL's I've set). I've started working on rebuilding the app in cloud code using the Express.js module Parse provides so that all of my code is stored server side, but I was wondering how those using client side frameworks get around this obvious problem.
That's the issue with client-side code. Assume any code you send to the client is hacked, broken, and tampered with.
With JavaScript, your best bet is to use either Cloud Code and send AJAX or streaming data calls to the server, retrieve the data from the server at runtime (not super secure, but would fool some people), or accept that your code is vulnerable.
I typically work with frameworks in the MVC format, so I only expose a limited subset of the actual model via a REST API. I use both a client-side framework and a server-side framework. Any thing sensitive goes on the server.
I would like to manipulate my own custom http server using javascript.
For example I would like the server to send an email based on ajax data received from a javascript page hosted from the server.
Another use would be to open a connection at an arbitrary port to an arbitrary web address and receive data from the connection.
Is there a protocol or framework to do this ?
You have used all the keywords and know all the techs you need to use:
You need AJAX to allow JavaScript to asynchronously connect to (and interact with) your webserver
You'll need a server-side processing language to do all the emailing business
The way you will do it will inevitably depend on the language. For example, if you're using PHP, the mail() function provides a simple way to send email... whilst the HTTP requests you speak of can sometimes get rather hairy.
A server-side environment like Node provides the opposite. Mails are hard to send - HTTP requests are trivial.
If you only know JS, I recommend you stick to Node, which takes JS scripts as directives.