cancel
Showing results for 
Search instead for 
Did you mean: 

client side javascript: get json data from share webscript

michaelp
Confirmed Champ
Confirmed Champ
Hi folks,

I am stuck atm.

I have a repo webscript and a share webscript. The share webscript gets some json data from the repo webscript. Now I want to get the json data from the share webscript to the client side javascript using Alfresco.util.Ajax.jsonGet() or something similar. My problem is that the only error message I get is "undefined" and nothing else 😕

The web scripts are working fine.

Here my client side javascript:


Alfresco.util.Ajax.jsonGet(
   {
      url: Alfresco.constants.PROXY_URI + "/jsontest/getJson" ,
      successCallback:
      {
         fn: function(response)
         {
             if (response.json)
               {
               var id= response.json.properties["id"];
               Alfresco.util.PopupManager.displayMessage(
                  {
                     text: id
                  });
               }
            },
            scope: this
         },
      failureCallback:
      {
         fn: function(response)
         {
            var error = "Error (failureCallback): " + response.responseText;
            Alfresco.util.PopupManager.displayMessage(
               {
                  text: error
               });

            },
         scope: this
      }
});


Is the code even working and extracting the json data properly? As I said the only message I get is "Error (failureCallback): undefined". All I want is that my var id has the value of the retrieven json data from field "id".

Can someone help me please? I am no javascript expert 😕

Thank you in advance
2 REPLIES 2

lementree
Champ on-the-rise
Champ on-the-rise
Hi Michael,

To solve the issue, read response as below.

response.serverResponse.responseText

Regards,

Wow many thanks!

EDIT: working like a chamr with


var json = JSON.parse(response.serverResponse.responseText);
var id = json["id"];


Many many thanks !!!