← Back to team overview

dhis2-devs team mailing list archive

Re: Web portal CORS/preflight problem

 

Dear Jan

I think cross domain problem is solved but more problem arise. I added the
jquery js script line but there is no chart. I think as i use
https://code.jquery.com/jquery-2.1.4.min.js' the calling of chart might
changed. the source I used is as :

<head>
<title>DHIS2 Web Portal</title>

<link href="style.css" rel="stylesheet" type="text/css" />
<link href="//fonts.googleapis.com/css?family=Lato:400,700"
rel="stylesheet" type="text/css" />

<link rel="stylesheet" href="//
dhis2-cdn.org/v217/ext/resources/css/ext-plugin-gray.css" />
<script src="//dhis2-cdn.org/v217/ext/ext-all.js"></script>
<script src="//dhis2-cdn.org/v217/plugin/chart.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js";></script>

<!-- Custom CSS -->

<style type="text/css">
li {
    float: left;
}

.chart {
    border: 1px solid #ddd;
    margin: 10px;
}
.chart.wide {
    width: 800px;
    height: 450px;
}
.chart.tall {
    width: 600px;
    height: 920px;
}
</style>

<!-- Login and initialize charts -->

<script>
var base = 'http://localhost:8080/dhismohfw19/';

$.ready(function() {
  $.Ajax.request({
    crossDomain: true,
    url: base + "dhis-web-commons-security/login.action?authOnly=true",
    method: 'POST',
params: { j_username: "view", j_password: "DGHS1234" },
    success: setLinks
  });
});

function setLinks() {
  DV.plugin.getChart({ url: base, el: 'chartA1', id: 'LjfRM4pSC0h' });

  DV.plugin.getChart({ url: base, el: 'chartA2', id: 'aR9w2QFpfW7' });

  DV.plugin.getChart({ url: base, el: 'chartA3', id: 'Pck5tyxraa3' });
}
</script>

</head>

<body>

<header>
  <h1>Data Visualizer Chart Plugin</h1>
</header>

<menu>

<p>This page illustrates the use of the Data Visualizer plugin which can be
used to embed dynamic ExtJS charts into a Web page. You can embed charts
pointing to pre-defined charts in DHIS, or select custom indicators,
periods and org units to create dynamic charts. View the source of
this page to see how it is done.</p>
</menu>

<section>

<h3>Predefined charts</h3>

<ul>
  <li><div id="chartA1" class="chart tall"></div></li>
  <li><div id="chartA2" class="chart wide"></div></li>
  <li><div id="chartA3" class="chart wide"></div></li>
</ul>

<p style="clear:both"></p>

</section>

</body>
</html>


On Thu, Aug 27, 2015 at 4:24 PM, Jan Henrik Øverland <
janhenrik.overland@xxxxxxxxx> wrote:

> You need to do this part
>
> Ext.onReady( function() {
>   Ext.Ajax.request({
>     crossDomain: true,
>     url: base + "dhis-web-commons-security/login.action?authOnly=true",
>     method: 'POST'
>  ....
>
> with jquery instead of Ext.
>
> See the code that Morten posted.
>
> On Thu, Aug 27, 2015 at 12:19 PM, Hannan Khan <hannank@xxxxxxxxx> wrote:
>
>> Thanks Jan.
>>
>> I added <script src="//code.jquery.com/jquery-2.1.4.min.js
>> <http://code.jquery.com/jquery-2.1.4.min.js>"></script> in the <head>
>> but still I get the error. What did I do wrong?
>>
>> Regards
>>
>> Hannan
>>
>> On Thu, Aug 27, 2015 at 2:49 PM, Jan Henrik Øverland <
>> janhenrik.overland@xxxxxxxxx> wrote:
>>
>>> Hi Hannan,
>>>
>>> I have done some testing and it seems the bundled Ext version is getting
>>> old. CORS is not working well with it.
>>>
>>> We need to look at this, but for now just include
>>> https://code.jquery.com/jquery-2.1.4.min.js (minified, only 84k) and do
>>> the authentication with jquery.
>>>
>>> The good thing about CORS is that you can simply do a normal ajax
>>> request and the browser will take care of the rest.
>>>
>>> On Thu, Aug 27, 2015 at 10:37 AM, Hannan Khan <hannank@xxxxxxxxx> wrote:
>>>
>>>> Dear Alex
>>>>
>>>> Thank you for sharing the resources. but the problem still persists. i
>>>> write as following:
>>>>
>>>> Ext.onReady( function() {
>>>>   Ext.Ajax.request({
>>>>     crossDomain: true,
>>>>     url: base + "dhis-web-commons-security/login.action?authOnly=true",
>>>>     method: 'POST',
>>>>
>>>> Please check.
>>>>
>>>> Regards
>>>>
>>>> Hannan
>>>>
>>>> On Thu, Aug 27, 2015 at 1:00 PM, Alex Tumwesigye <atumwesigye@xxxxxxxxx
>>>> > wrote:
>>>>
>>>>> Dear Khan,
>>>>>
>>>>> Look at this
>>>>> http://api.jquery.com/jquery.ajax/
>>>>> Read about crossDomain, by default it set to false so you may need to
>>>>> set it to true.
>>>>>
>>>>> Ideally, in your ajax request, add crossDomain:true
>>>>>
>>>>> Alex
>>>>>
>>>>>
>>>>>
>>>>> On Thu, Aug 27, 2015 at 9:53 AM, Mark Polak <markpo@xxxxxxxxxx> wrote:
>>>>>
>>>>>> Hello Hanna,
>>>>>>
>>>>>> Did you add http:// (or https:// if you use a secure line) in front
>>>>>> of the IP address?
>>>>>>
>>>>>> On the demo instance this is a bit confusing as the examples do not
>>>>>> show that but it is required for it to work correctly.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Mark
>>>>>> ________________________________________
>>>>>> From: Dhis2-devs [dhis2-devs-bounces+markpo=
>>>>>> ifi.uio.no@xxxxxxxxxxxxxxxxxxx] on behalf of Hannan Khan [
>>>>>> hannank@xxxxxxxxx]
>>>>>> Sent: 27 August 2015 08:29
>>>>>> To: DHIS 2 developers
>>>>>> Subject: [Dhis2-devs] Web portal CORS/preflight problem
>>>>>>
>>>>>> Dear Experts
>>>>>>
>>>>>> I am facing problem to creating Web Portal, facing problem CORS.
>>>>>> First I try portal from 103.247.238.68 not working and then put this
>>>>>> address in the white list of the dhis2 server at 103.247.238.68:8080<
>>>>>> http://103.247.238.68:8080>. But but still having the same problem
>>>>>> the error message is 'which is disallowed for cross-origin requests that
>>>>>> require preflight'.
>>>>>>
>>>>>> Now how I resolve this? The script is similar as on the developer
>>>>>> guide, page 49.
>>>>>>
>>>>>> Please advice.
>>>>>>
>>>>>> Regards
>>>>>>
>>>>>> Hannan
>>>>>>
>>>>>> _______________________________________________
>>>>>> Mailing list: https://launchpad.net/~dhis2-devs
>>>>>> Post to     : dhis2-devs@xxxxxxxxxxxxxxxxxxx
>>>>>> Unsubscribe : https://launchpad.net/~dhis2-devs
>>>>>> More help   : https://help.launchpad.net/ListHelp
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Alex Tumwesigye
>>>>>
>>>>> Technical Advisor - DHIS2 (Consultant),
>>>>> Ministry of Health/AFENET
>>>>> Kampala
>>>>> Uganda
>>>>>
>>>>> IT Consultant - BarefootPower Uganda Ltd, SmartSolar, Kenya
>>>>>
>>>>> IT Specialist (Servers, Networks and Security, Health Information
>>>>> Systems - DHIS2 ) & Solar Consultant
>>>>>
>>>>> +256 774149 775, + 256 759 800161
>>>>>
>>>>> "I don't want to be anything other than what I have been - one tree
>>>>> hill "
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Mailing list: https://launchpad.net/~dhis2-devs
>>>> Post to     : dhis2-devs@xxxxxxxxxxxxxxxxxxx
>>>> Unsubscribe : https://launchpad.net/~dhis2-devs
>>>> More help   : https://help.launchpad.net/ListHelp
>>>>
>>>>
>>>
>>
>

Follow ups

References