Open web apps with webservices

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

fixed it! :smiley:

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.

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 :slight_smile:

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.