I'd like to send a JSON rpc to a remote web-server. The client-side of my application must be completely javascript. The choice of the client library should be independant from the json-rpc implementation on the server-side. I don't need json-over-http. Simple json objects over tcp/ip is enough for my use-case.
Thanks
You could try jsolait. AFAIR it has support for JsonRPC 1.0 over sockets.
Since you are connecting to a remote web server, you will have to use HTTP.
You can use XMLHttpRequest for this from Javascript or you can use a library such as jquery that packages it up in an easier to use API. Many Javascript libraries support this functionality.
I would use Ajax with jQuery. Dead simple.
JQuery Post Documention
Related
Ive been looking around and i cant find an answer for creating a Pure JavaScript Proxy server without node.js. If anyone has an answer please comment. I’m wondering if its possible because i want to set up my own proxy server without node.js so its fully web based.
EDIT 2
So now that i know that i cant directly create a proxy server on the web, is there a way to do it in Java? (Or a similar language)
You cannot accomplish having a proxy server (or any type of server) in the browser. Reason is that proxy servers require a static host that would map data to and from the server.
You will at least need to have a client/server type architecture to accomplish what you're trying to do.
Take a read at: https://en.wikipedia.org/wiki/Proxy_server
I have a simple html page being served by express on a node.js server and in the client side javascript i want to access some server side variables. I tried googling around for a solution but didn't see a straight forward solution without using some sort of templating engine.
So if i need to access a variable on the server from a client side JS served from the same host, what do i need to do?
To access the variable on the client, you'll need to expose it inside of a script tag, there are a few node modules that can help you with it (ex: express-state) https://www.npmjs.com/package/express-state, but you'll need a templating engine to generate the html required for it. You can use a variety of templating engines when working with express. If you use express generators straight out of the box it should come with jade and you can use different options on the generators to use other templating engines. See here for express generator options http://expressjs.com/en/starter/generator.html
Create an API to expose your variable:
app.get('/myvar', function(req, res){
res.send(varYouWantToSend);
});
Then in the client-side make a call for that API with a http GET request. The url for the API would be www.yoursite.com/myvar in this example.
You could try using this lib:
https://github.com/siriusastrebe/syc
and if you want to implement yourself look into Ajax. Jquery have a pretty simple ajax wrapper (http://api.jquery.com/jquery.ajax/). offcourse you need to open corresponding urls on the server to return / set the values.
Try socket.io http://socket.io/ it uses websockets on modern browsers and gracefully degradate to older technologies like AJAX with older browsers, leaving user experience the same.
Check out details here Web Socket support in Node.js/Socket.io for older browser
I want to build a XMPP web-based chat client to add on to outlook web access. I've read that Javascript is problematic.
Could I use html5 websockets using the openfire server and the Javascript(strophe)?
I've read on other solutions that include using flxHR, a flash library.
Which would be better?
Just use an existing XMPP/BOSH library for JavaScript, such as Strophe.js. You don't need to wait for WebSockets.
A lot of the WebSocket libraries, technologies and services provide fallback for browsers that don't support WebSockets. This is generally done via Flash but some libraries also fallback to HTTP streaming or polling.
Have a search for WebSockets on the following page for available technologies:
http://www.leggetter.co.uk/real-time-technologies-guide
This is the node-chat I'm inquiring about:
http://github.com/scottgonzalez/node-chat
How are the messages being passed to the server?
websocket comet ajax?
How does it work?
Is what it's using scalable?
Thanks.
it uses node.js running as a specialized http-server, reacting via a REST-like API to requests, delivering json.
the client is a jquery enhanced "website" which polls its information from the server via jquery.ajax() (the json-chunks could be fetched via jQuery.getJSON() as well [just normal http fetch]).
since it is just a little show-off i doubt it is "scalable" in terms of "distribute this like hell over thousands of machines to handle millions of users".
Using the ActiveXObject object on IE. How can I submit a cross-domain request?
Setup a server-side proxy to make the request for you. Then invoke the proxy (locally) using AJAX.
I would really recommend using a javascript framework when dealing with ajax request. That way you don't have to get into the intricaties of each browser. My personal favorite is jQuery: http://www.jquery.com/
Now, when it comes to cross-domain, you have two situations:
Data is only available as XML => use a server-side proxy: http://ajaxpatterns.org/archive/Cross-Domain_Proxy.php
Data can be retrieved as JSON using JSONP: http://www.ibm.com/developerworks/library/wa-aj-jsonp1/
Whenever possible, when it comes to a web browser, I'd recommend JSONP for its simplicity. However, things can get tricky in case of error so, again for jQuery, I'd recommend the following plugin: http://code.google.com/p/jquery-jsonp/