This question is for my curiosity only:
Is it possible to make a HTTP request from a backend server to a web browser, that is to say I have a HTTP server ON the web browser to listen for incoming HTTP requests?
Cause I want to use frontend <-> couchdb directly thus dumping the backend server .. but then i wondered how i would do normal processing when the database javascript is not sufficient.
That thought made me think of this question.
Generally speaking — no.
There are some exceptions, Opera has a feature called "Unite" which allows it to run a web server (this is not turned on by default!) as well as acting as a user agent. That wouldn't allow you to send a response to a request that hadn't been made though.
Most web browsers don't have a web server and they are unable to accept HTTP requests. Maybe there is an extension for Firefox, but that's not a typical use case.
Depending on what you are trying to achieve, using Comet or long polling could work for you.
Related
It is easy to create an AJAX request to obtain resources from an HTTP server. But I am trying to find a way to create a TCP connection to a server to obtain certain resources, in the browser.
HTTP works over TCP, so I think that the way AJAX creates an HTTP request, the modules they use can be used to do the same, since a TCP connection has to be established before creating an HTTP request.
So, I want to know how does the AJAX library create an HTTP request and what does it use so that I can do the same in my code.
Your browser will probably refuse to do this, for good security reasons.
When you visit a web page that contains javascript, that code gets pulled down and starts to run inside your browser (assuming you have allowed javascript). That's handy, because it allows the website to be dynamic and do useful things for you. But do you want to allow that javascript to read your hard drive? I can assure you, you do NOT want that. Do you want to allow it to make arbitrary TCP connections? I can assure you that you don't want that either. The browser WILL allow the code to go back to the same server and push and pull data - that's what the AJAX library is doing. Nowadays browsers also allow javascript to initiate WebSocket connections, which is a little risky, but perhaps not as wide open as arbitrary TCP connections.
I am trying to implement an API on my system, but every time of the problem, I do locally ... via server on hosting, handle calmly.
I have a question that is as follows, does XAMPP accept Ajax? I searched the internet and found nothing about it.
Ajax is just a term for making an HTTP request from client-side JavaScript without leaving the current webpage.
As far as the HTTP server is concerned, there is no real difference between an HTTP request initiated using Ajax and one initiated using any other method.
The only proviso is that browsers implement a Same Origin Policy which can lead to the browser forbidding JavaScript from reading the response (or, in the case of preflighted requests, making the request in the first place) unless the server adds headers granting explicit permission.
Apache HTTPD (the HTTP server distributed with XAMPP) is quite capable of being configured to add these headers, but it is more common to add them using a server-side programming language (such as PHP).
It should work, I've done it anyway. You may have to check the error log to find out why its failing. First off what does your browser log for code or connection issues, this will detail if its a CORS issue (F12 in chrome for me)? If the issue isn't there then you may have to check the Xampp log: \xampp\apache\logs\error.log for that application.
Also can be done this way:
https://stackoverflow.com/a/38347316/10980320
Yes, XAMPP accepts AJAX requests! All requests, no matter whether they're through AJAX or just directly visiting the page through a browser, request and receive the data in a specific way. As far as I know, there isn't really a way to not support one type of request or another, although they can probably be blocked.
Feel free to correct me.
Could ajax be used on the client side javascript to function as an in-the-background web spider? You'll have to excuse the vagueness of this post because I really have no idea where to begin technically in terms of the code and there is nothing online about a program like this.
You can use a cors proxy type script in order to do these Ajax requests client side via javascript. Look on Github for 'cors proxy', and set that up in your Node.js environment, then pass all of your ajax calls client side through this proxy.
Yes its possible but with some restrictions, meant only to be done from a specially-configured browser, not for arbitrary users to just run:
For chrome, open it using the command-line parameter --disable-web-security.
now you can do cross domain and such.
I assume you just want it for using yourself as a server and not on a public web page.
You cannot make ajax requests to different hosts, so no.
How can I make my javascript client application receive socket requests?
I mean not response on request, but request itself.
Javascript is running in browser without HTML5.
The thing is that I want my web page to reload changed content but without the need of making request to the server each several minutes.
I hope that a server can make some request to javascript on the page, making it refresh the page. If not what could you suggest instead javascript in this scope.
Many browsers that support HTML5 implement WebSocket interface. WebSocket allows two way communication, so browser and server can send requests. Check this post for more info What browsers support HTML5 WebSocket API?
If your browser doesn't support WebSockets you could try WebSocket emulation written in Flash/JS from this site https://github.com/gimite/web-socket-js
If this is also not suitable for you then the last option is "long polling". In this case browser ask server for some data and if server does not have any information available for the browser it doesn't send empty response. It holds the request and waits for new data to be available. Browser after receiving new data immediately ask server once again.
Check these links for more information:
http://en.wikipedia.org/wiki/Push_technology
http://en.wikipedia.org/wiki/Comet_(programming)
Yes and No.
No
Javascript running in a browser environment can't listen to sockets since it's running in a sandbox with limited capabilities.
Yes
However, JS is a full fledged programming language, so if you have it running in an environment where it is not crippled yes, it can do that and more.
A nice example is node.js - http://nodejs.org/
Wiki page - http://en.wikipedia.org/wiki/JavaScript#Uses_outside_web_pages
I'm prototyping a realtime notification mechanism using http over port 80. The aim of the project is to allow a Flash application to respond to an event on a remote server quickly (specifically an inbound phone call being connected to a phone next to the computer.) Polling is one approach, but is too slow. Currently I use a socket connection to get low latency notification of the events on the server, which works well but isn't firewall friendly. I don't want to install anything except Flash, or Silverlight on the client. Cross compatibility of browsers isn't a concern - in this application I can specify what browser the client uses but IE is preferred.
I've made a server HttpHandler in .NET which never closes the connection and sends the "events" to the client by writing out bytes to the http response stream (ConnectedClientContext.Response.OutputStream.Write etc) and I have a .NET client application which can read these messages okay.
My Question:
Can I receive the bytes from the server over HTTP as they arrive using JavaScript, Flash or Silverlight? So far I can only find a way to get notified of the "download progress" and don't get the actual bytes until the response is closed - I want them as they arrive.
Best Regards,
Daniel
I don't know about Flash but in Javascript (by which you mean in browser) and Silverlight you are limited pretty much to the http protocol.
You can use the AJAX Http Streaming pattern. The basic ideas which is different from what you are trying is that as soon as data is available outstanding request ends and a new is immediately initiated asychronously, mean while your client process the newly arrived data.
Silverlight gives you more options since is HTTP stack is purely asynchronous but you can get your hands on the stream to you as soon as data starts to arive by setting the HttpWebRequest.AllowReadStreamBuffering to false. (Unlike XmlHttpRequest which always buffers).
it's very easy to use the Comet ideas for notifications. you don't even have to use a comet-specific framework. simply do an ajax request with a callback on answer, wrap this on a loop and you have an event loop, just like a GUI app. on the server side, don't bother answering the request until there's either an event, or a timeout (which is just a 'null' event).
Flex and Flash have several AMF/XML remoting libraries available that support data pushing. I would certainly look into that.
http://raghuonflex.wordpress.com/2008/04/17/data-push-in-flex-with-backend/
These libraries use a Comet - like implementation to achieve this.