0
votes

I'm trying to use the google chart api in an XPages application. I'm using the code example given by the documentation : https://developers.google.com/chart/interactive/docs/php_example#exampleusingphphtml-file

I have to replace the call to the php page by a call to an LS agent.

      var jsonData = $.ajax({
      url: "getData.php",
      dataType: "json",
      async: false
      }).responseText;

So my code goes to :

     var jsonData = $.ajax({
      url: "http://server/database/agent?openagent",
      dataType: "json",
      async: false
      }).responseText;

On my local domino server, it works fine. On the production domino server, I get nothing. The chart is not drawn. After debugging the js client side, it seems the ajax call is expecting an authentification even if I had to log in before.

The anonymous access is not allowed on both servers. The security level seems to be same on both environments

Any help will be welcome (or any other way to proceed if I'm wrong).

Thank you

2
Are you sure that Anonymous is not allowed to access server/database/agent?openagent on your local Domino server? Check the ACL of the database. Also, try accessing server/database/agent?openagent directly on both your local Domino server and on the production server.Per Henrik Lausten
I've just checked the call of the agent on both servers. on the both servers, I have to log in before getting the agent results Anonymous entry is set as no access in LCA on both databases I tried also to implement the NetDeamon's solution, and no more results.Techn0fil
If you want anonymous to be able to use the agent, you should give Anonymous the correct access in the ACLPer Henrik Lausten
I don't need the anonymous access. I need to run the agent with the context of the user : the agent gets data for the current user. I will try to transform the call of the agent by a use of an Xpage. May be it will solve the issue.Techn0fil

2 Answers

0
votes

If you are able to draw the google chart in your local server, but not in production server, this means it is your server issue.

You can add authentication header in your jquery ajax call to make authenticated ajax request

$.ajax({
  headers: {
    "Authorization": "Bearer <TOKEN HERE>" 
  }
})

You can also send username and password in jquery ajax call, to make authenticated request. Here is the sample code from the link

$.ajax({
    type: 'GET',
    url: 'url',
    dataType: 'json',
    //whatever you need
    beforeSend: function (xhr) {
        xhr.setRequestHeader('Authorization', make_base_auth(user, password));
    },
    success: function () {});
});

function make_base_auth(user, password) {
    var tok = user + ':' + password;
    var hash = btoa(tok);
    return 'Basic ' + hash;
}
0
votes

at the end, I tried to run the ajax request through dojo instead of Jquery. My codes became this one :

var jsonData = dojo.xhrGet({
  url: "http://server/database/agent?openagent",
    handleAs:"json",
    ...
})  

I did no changes at the security level or anything else.

I do not understand why the jquery syntax is not working as well the dojo syntax.

anyway, it is working now.

Many thanks to all for your suggestions