power
(Power Mukisa)
March 22, 2015, 1:32am
1
Hello, am trying to get locations using webservices.rest url: “http://demo.openmrs.org/openmrs/ws/rest/v1/location ” as the url, but i get an error “XMLHttpRequest cannot load http://demo.openmrs.org/openmrs/ws/rest/v1/location . No ‘Access-Control-Allow-Origin’ header is present on the requested resource” . and am not familiar with setting access control with javascript in Polymer.
here’s a snippet of the code:
<core-ajax id="ajax"
auto
url="http://demo.openmrs.org/openmrs/ws/rest/v1/location"
on-core-response="{{locationsLoaded}}"
handleAs="json">
</core-ajax>
Anyone know a way around this?
Thanks
sunbiz
(Saptarshi Purkayastha)
March 22, 2015, 5:45am
3
For authentication… use the HTTP header - Authorization: Basic … There are a number of threads on openmrs mailing list as well as wiki pages about authentication to OpenMRS rest services.
power
(Power Mukisa)
March 22, 2015, 8:27am
4
hey @sunbiz , i looked around for that documentation on authorization, but couldn’t find it, and time it is running out. Please send a link that i can refer to. Thank you
sunbiz
(Saptarshi Purkayastha)
March 22, 2015, 6:17pm
5
If you are using jQuery 1.7.2 and higher, use something like the below example code
$.ajax
({
type: "GET",
url: "/openmrs/ws/rest/v1/location",
dataType: 'json',
async: false,
username: username,
password: password,
data: '{ "comment" }',
success: function (){
alert('Thanks for your comment!');
}
});
It has the username password that will be sent as Basic auth against the openmrs services.