← Back to team overview

dhis2-devs team mailing list archive

Problem with cross domain when try to get data in Javascript

 

Dear devs,
I'm writing a script to retry data in Javascript.

<head>
<script src="http://code.jquery.com/jquery-1.11.3.min.js";></script>
</head>
<script>


var username = "admin";
var password = "district";

function base_64_auth(user,password) {
      var tok = user + ':' + password;
      var hash = btoa(tok);
      return "Basic " + hash;
 }

 var auth = base_64_auth('admin','district');

$.ajax
  ({
    type: "GET",
    url: "http://lovad.dyndns.org:8080/dhis/api/analytics.json";,
     beforeSend : function(req) {
          req.setRequestHeader('Authorization',auth);
     },
contentType: ('application/x-www-form-urlencoded; charset=UTF-8'),
//data: myData,
    crossDomain: true,
    dataType: 'json',
    async: true,
    data:
"dimension=pe:2014&dimension=dx:gDjsoVCV1IS;WwZO3ZsiEfY;e260Wp7azgU;oWOegwmH8R6;BFoZmB1niCW;RDNNa3wlbot;WL2hJUrSAYF;LqZs55KPchi;lSNZ1fA6bgU;ogjRBqBvE4y;dEbYmPSIT7I;INsWGhrZajt;kXa8gZMieei;dp6B5yT6wlB;EhTC6pIq8Be&filter=ou:Am2jVEuE3gE&displayProperty=NAME",
    success: function (){
    alert('Thanks for your comment!');
    }
});

</script>


But then I've received this return error. I may because of cross domain
issue.
Notes: I've added my WAN IP address into settings -> access

index.html:1 XMLHttpRequest cannot load
http://lovad.dyndns.org:8080/dhis/api/analytics.json?dimension=pe:2014&dime…gZMieei;dp6B5yT6wlB;EhTC6pIq8Be&filter=ou:Am2jVEuE3gE&displayProperty=NAME.
Response for preflight is invalid (redirect)


Is it possible to retry data by Javascript with basic auth?


Thank you very much and best regards,

-- 
THAI Chuong
YM/Skype : thaichuong159
Phone: (+84) 918776134