cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco.util.Ajax.jsonGet results in a 'not well-formed' exception

mario_fliegner
Confirmed Champ
Confirmed Champ
Hi all,

I'm struggling with a webscript, that I'm calling inside a custom form control to retrieve values for a dropdown. I don't get the response parsed at all. The reason may be that the browser's error console says that the result is not well-formed!?

Here is the JacaScript code, that invokes the webscript:
<javascript>
function selectArchiveId(currentValueHtmlId) {
                        this.currentValueHtmlId = currentValueHtmlId;
                        var selectArchiveId = Dom.get(this.currentValueHtmlId);
                        this.register = function () {

                            Alfresco.util.Ajax.jsonGet({
                                url: Alfresco.constants.PROXY_URI + "my/company/feature/getArchiveIds",
                                successCallback: {
                                    fn: function(res) {
                                        var results = Alfresco.util.parseJSON(res.serverResponse.responseText);
                                        alert(results);
                                    },
                                    scope: this,

                                },
                                failureCallback: {
                                    fn: function () {
                                    },
                                    scope: this
                                }
                            });
                        }; //this.register

                        this.register();
                    }
</javascript>

The alert pops up with content:

[object Object]

But I can't access it. The content is always null or undefined. The code above is based on this topic: https://forums.alfresco.com/forum/developer-discussions/alfresco-share-development/dynamic-selectone...

The response from the webscript is:

{"archiveIds":{"K1":"NSP System","Z1":"PEI System","Q1":"KKK Dev System","Q2":"KKK Dev System","Z3":"PEI System","Z2":"PEI System"}}

Something is returned…
The error message from the browser is attached as image.
I think it's related to the function used for the webscript call: Alfresco.util.Ajax.jsonGet ?
But if I try to call the webscript by the Alfresco.util.Ajax.GET function, then this function is not found.

If you are interested in the webscript definition itself:

<webscript>
    <shortname>Get Dropdown values</shortname>
    <description>
        Get all dropdown values for archiveId
    </description>
    <url>/my/company/feature/getArchiveIds</url>
    <format default="json"/>
    <authentication>user</authentication>
    <transaction>none</transaction>
    <family>my company</family>
</webscript>


How do I call the webscript correctly? Or how I'm able to access the response? Does anybody know?

Thanks,
Mario
2 REPLIES 2

kaynezhang
World-Class Innovator
World-Class Innovator
Have you ever tried

             successCallback: {
                                    fn: function(res) {
                           if (res.json !== undefined)
                           {
                                           var results = res.json;
                                           alert(results);
               }
                                    },

staifresco
Champ in-the-making
Champ in-the-making
Hi Mario,

I ended up on this post looking for a way to use the object Alfresco on my webscript, I can see u are using it, for exampel to make the ajax call with Alfresco.util.Ajax.jsonGet().

Can u tell me how can I add it to my webscript ?

I thought it was automatically added cause I didnt find any documentation on how to use it, but then if I try to use it I get an undefined object error.

Do u have to import on your ftl header from Alfresco or it gets included with some particular configuration ?

Thanks

Enrico