I made an Angular app and I wondering if its possible that Angular send JSON information like a server.
For exemple I'd like that when we access an URL of my app 'localhost:4200/test', the answer is an JSON and not a HTML page.
In other words, I want to be able to collect data with POSTMAN when I request an route of my Angular 4 app.
Thank for any informations.
P.S: I'm not sure that "RENDER" is the right term because when I look for "Angular render JSON" it's always about display a JSON in an HTML page :/
I could be wrong, but to my knowledge this is not possible. You want your client/browser application to behave like a server. This is not possible as you cannot setup a socket listener in a browser.
If you host your application in a shell like electron it would be possible to start a nodejs server on the local machine. However technically this isn't your angular application any longer.
Related
This is most likely a repeated question.
The closest I got to an answer was here: execute a Nodejs script from an html page?
Yet, I still can't understand.
So here's the situation:
I have an express server setup with the following files:
Express App
server.js
index.html
and right now I want the html folder to have a button, that calls a function set in the node.js file.
Tell me if more information is needed, thanks!
EDIT:
Im remaking the question to be more clear.
I am using an express server to present a website, that present a button saying " Power Off", I want this button to be able to execute an action on my server computer, that action being a terminal command to power it off.
I wanted to know how could I make said button, written in HTML, hosted on the server but presented to the client, to interact with the server.js file hosted on the server, which would have a function set to execute said command.
thanks!
You need to understand a little better how the client/server architecture of a web page works and where code actually runs and how the client and server communicate with one another.
You can't call a function directly on your node.js server from an HTML file. The HTML file is in the client's browser. The node server is your web server, far away from the client's browser on different computers. Though it may seem like your HTML is on your node.js server because it's in a directory on that server, that's only where it is stored. When the browser requests that page, your node.js server sends the HTML to the client's browser and it is rendered back in the client browser and that's where the Javascript in that page runs (in the client's browser, far away from your node.js server). This is a client-server architecture. The HTML page is running on the client. The node.js server is on your server - different computers.
If you want to communicate with the node.js server from the web page, then you use Javascript in the HTML page to make an Ajax call from the Javascript in the web page to the node.js server (An Ajax call is an http request). You then configure a route in the node.js server for that specific Ajax call and you can then write code in node.js to do whatever you want to happen when that Ajax call is received. It can carry out some operation on the server, it can retrieve data and return it to the client, etc... You can optionally send data with the Ajax call (either as query parameters for a GET request or as body data for a POST request) and then the server can optionally return data back to you (often as JSON, but it can be any format you like).
I'm not an expert with Node, but I think what's happening here is blurring the lines between server and client. Even though both use JavaScript, there's a distinction. NodeJS could easily be replaced with Ruby, PHP, Java, whatever-backend-language-you-like, and this distinction would apply in the same way it does when you use JavaScript on the server. There's no differerence.
Server-side code executes on the server. Client side code executes on the client (the browser). If you need to call a NodeJS function (assuming it has to interact with the other server side code such as databases etc) then you can send a request, either via AJAX or standard HTTP, to the a route on the server and call that function within the route.
On the other hand, if the function is generic enough and doesn't involve any specific Node code then you can simply add a script tag with your JavaScript file to the index.html page.
There is a difference between server and client. You cannot just call a function on a server from a client directly, there is more to just that. If you wanted to, you could do it by routing a path to wherever and making an HTTP request to that path, or even, using other protocols like WebSocket if you need to communicate both ways.
I have been developing an app that has to access a DB and return data has charts in a web page. since it is to be added to another software i had to create it as a local server / servce, using self host web api, returning the data as json so i can read it in my html file and create the charts.
The server / service works, but my problem remains on the client. I don't know if i have to create another project for my html or if i just add a folder with my html and all css and javascript.
Basically when i run it i have to display my html file.
I have been looking the web for examples / solutions but i can't seem to find one that will help me, i've checked:
creating help pages with T4, but it includes all my css and js files in my html and when i want to change something i have to remove the include, debug and include it again;
create a web app but when i run it it creates me 2 servers, the one i've created and the web page server, although my web page will access it using angularjs, i can't have the second server;
I'm a little lost on how i will do it.
Can someone give me some help?
I'm using VS2010, self-host WebApi, console app, entity framework, angularjs, nvd3 and d3.
thk
If you have developed your project using MVC4 you can create view/controller related to report in webapi project.Point add html files to this view.This won't create 2 servers.
I have a spring MVC app and a joomla "showcase web site".
How can I display data from spring MVC in my joomla showcase site?
My first attempt was to create a simple joomla module with inside jqgrid. But I discovered that many browser deny JSON cross domain and that this attempt is not good.
I also tried with an IFrame.. but I don't like this approach..
The current attempt is to export data from MVC app in RSS. I've installed an rss module in joomla and it works. But it's limited in search and sorting operation.
It would be great to find a way that permit to filter and sort data using some existent and open joomla module.
Does anyone have suggestion on proper export data tecnology and a related module?
#mserioli
You should use the php curl, and in your module you make the request using the GET or POST method to retrieve data (json/xml) from your MVC app
Has anyone tried reading and writing data to/from COM ports in webpages. I am running Apache webserver. Could anyone one suggest me about what scripting should I use to access data in html pages from COM ports on the system ?
Thanks
There is currently no way to do this directly from HTML 5 (except perhaps for maybe on the blackberry tables OS or BB10 using webworks (would also be client side), but I have not personally tried this). If you are trying to read serial data on the server and showing the result in an HTML document it's quite easily done using javascript to sent post requests to your web-server. doing the work on the server and responding, and interpreting the server's response in the javascript.
There's lots of online guides for sending post requests from javascript asynchronously, for instance: JavaScript: Sending POST, redirecting to response.
On the server side, lots of options available. You can use PHP-serial to read serial data: http://code.google.com/p/php-serial/, or if it's not a PHP server there are libraries available for most languages. Or, if you don't like PHP-serial you can use your server language to call another executable/script on the system to do the serial reading (that external program can relay the read data via stdout or file output). Either way, the webserver can then respond to the HTTP request simply by printing out the data, and your client-side javascript can read the response body to retrieve that data.
I have to load data for a different url the page will run on the android browser and will load content from remote server .
I have to use dojo so I tried with dojo.xhrGet , it does'nt load the data so when I red the reference guide I saw that that method has some limitation with external url's .
So what I have to do now if I have to call a REST service with dojo .
the REST service URL on the remote server:
http://192.168.1.65:9080/RAD8JAX-RSWeb/jaxrs/customers/accounts/111-11-1111/
and the data that I should see
[{"id":"001-111001","balance":12345.67},{"id":"001-111002","balance":6543.21},{"id":"001-111003","balance":98.76}]
please help me with a method that can fix my problem I dont know dojo well I'm blocked right now because I can't use the data between two application they can't communicate
Your question is unclear, but I think you are saying you want to load data from a different domain to the main web page.
You cannot reliably use AJAX to load data from anywhere other than the domain of page you are visiting.
Almost all modern internet browsers deliberately block that, for the protection of their own users.
Instead, you will need to find some way of getting your server to relay the information.
So imagine currently you do:
Load page a.example.com/index.html
Page uses dojo to try to load b.example.com/data
You would instead need to do:
Load page a.example.com/index.html
Page uses dojo to try to load a.example.com/data
When the a.example.com server receives a request to load /data, it should connect (perhaps using cURL) to b.example.com/data and then output the same text.