admin管理员组文章数量:1429145
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 mand (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.
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 mand (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.
Share Improve this question asked Jan 18, 2013 at 16:40 user103583user103583 571 gold badge2 silver badges7 bronze badges2 Answers
Reset to default 5You're getting Access-Control-Allow-Origin
error because of the same origin policy built into browsers. By default, you'll get this error when your JavaScript and Server API do not originate from the same server:port
. To get around this, you need to specify the Access-Control-Allow-Origin
in the header of your HTTP response from the server.
To acplish this in KDB/Q, do the following:
.z.ph:{ "\r\n" sv ("HTTP/1.1 200 OK"; "Access-Control-Allow-Origin: *";
"Content-Type: application/json"; ""; (.j.j select from aTable)) }
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.
本文标签: javascriptHTTP GET request to KDB Process using AngularJSStack Overflow
版权声明:本文标题:javascript - HTTP GET request to KDB+ Process using AngularJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745525125a2661800.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论