Reputation: 20648
Hi I am quite new to java script and i am looking a working example to call back ends using java script channel API . I do not have any idea about channel API . Can anyone provide me a working example
Upvotes: 4
Views: 838
Reputation: 8471
If you're asking how to get a message from the backend to a javascript client: you can't send messages from a backend server to a channel created on a frontend server. This is because the app version number is included in the channel token, and backends have a different app version than frontends. You could, however, implement a servlet in your backend that calls createChannel and returns it to your frontend for inclusion in javascript that your frontend renders.
If you're trying to send a message to a backend from your javascript code, you won't be able to use XmlHttpRequest directly because of the same-origin policy (this assumes your clients are rendered from a non-backend instance). You could get around this using JSONP, or by routing XHR requests from your frontend to your backend in a frontend servlet.
Upvotes: 3