cancel
Showing results for 
Search instead for 
Did you mean: 

Send Json data on form submit and read through in Repository webscript

suman_nitt
Champ in-the-making
Champ in-the-making
When i do custom form (runtime form) submit, i make Ajax call to Repository webscript. I want to know how to pass Json data to the webscript. Also, I want to know how to parse Json data at controller javascript.

I also noticed, all root scoped objects are not available at controller javascript. I was not able to access document, script, etc. Because of that, i could not check the content type of the request.

Please help.
4 REPLIES 4

suman_nitt
Champ in-the-making
Champ in-the-making
Earlier i made Ajax call as Alfresco.util.Ajax.request. I changed it to Alfresco.util.Ajax.jsonPost, now i observe that the request body content type is application/json. But there is no data in the "Request payload".

I found there is something called "dataObj:", which i need to send while making Ajax call. Basically the dataobj will have json data, which is nothing but form input values. I don`t know how to read runtime form values and set in dataobj. Please help.

PS: Attached is the javascript code to create runtime form and to make Ajax call.

pylady
Champ in-the-making
Champ in-the-making
Hello,
Did you find a solution? I have the same problem.
Thank you!

muralidharand
Star Contributor
Star Contributor
Hi,
Can you please upload your javascript and mention in which control values you're not able to read ?
I used lot of custom share forms on Share, but I didn't faced this kind of problem.

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

You need to stringify the json and send it as data to post request sample as below for posting favorites

var url = "/alfresco/service/api/people/" +username + "/preferences";
    var dataObj = {
        "org": {"alfresco":{"share": {"documents": {"favourites":favourites }}}}
    };
    var data = JSON.stringify(dataObj);


    $.ajax({
        type: "POST",
        url: url,
        async: false,
        data: data,
        contentType: "application/json",
        complete: function (data) {
          
        }
    });