I am working on a web app using AngularJS with which I am quite inexperienced.
My aim is to have the user type some parameters into a text field, and then for a GET request to be sent out (using the $http service in Angular) using that parameter as one of the params in the GET request.
The target of the request is a KDB+ process (A proprietary column oriented database/language from KX Systems). This process can take a request in the form of:
http://servername:1234/?queryToRunHere[paramFromApp]
This call should return a JSON string. Due to the fact that the webserver and this process run on different ports I get the “Access-Control-Allow-Origin” error that prevents me from running this query to a different port. I have attempted to use the $http.jsonp command (since I read this allows remote fetching) however this asks me to provide a “&callback” parameter. This is not possible as KDB+ will interpret everything to the right of the “?” as an internal query.
I am not really sure how to proceed, but these are my ideas so far:
-
KDB+ provides an API for Java (but not as far as I am aware for JavaScript). Perhaps I could write some sort of web service in Java, which could then be called by angular, and which in turn would call KDB+ using its native API. The issue with this is that it creates another program to maintain, and also I am not sure how to go about writing such a service (what technology, framework, etc).
-
There is another way inside Angular that I don’t know about, or there is a way to not have to specify the callback parameter in $http.jsonp.
I would be grateful any help.
That error is usually only caused by different servers, its in order to prevent cross site scripting, the usual workaround is to add headers in your apache config. make sure both services are referred to with the same host name.
Alternatively the KDB+ response can be customized if you want though it may be tricky if your new to q.
.z.ph is what controls KDB’s processing of HTTP requests, you could overwrite it to process any parameters and return whatever you want. An example can be seen on the KX wiki.
KDB+ 3.0 and newer also provide web sockets which you may find more useful. They are handled by .z.ws.
An example of its use in javascript can be seen in Carlos Butlers’ WebStudio.
Hopefully these have provided you with workarounds for your issue.