Search code examples
javascriptalfresco

Retrieve data in javascript from jquery post


I want to perform a post action in the client side to call a javascript based webscript(server side ) in order to delete and element and do more stuff.

If i perform in the client side a post call like this

var data = {
  option: "erase",
  noderef: 5832
};

$.post(Alfresco.constants.PROXY_URI + "extractor-jdocs",
  data, 
  callback_function);

How can i manage to read "data" in the server side? (javascript)


Solution

  • You can call repo webscript/server side webscript from client side js.

    var data = {
      option: "erase",
      noderef: 5832
    };
    Alfresco.util.Ajax.jsonPost(
    
    {
    
                    url: Alfresco.constants.PROXY_URI + "mypostwebscripturl",
    
                    dataObj:data,
    
                    successCallback: {
    
                                    fn: function(res){
    
                                       alert("success");
    
                                       alert(res.responseText);                                                                                            
    
                                    },
    
                                    scope: this
    
                    },
    
                                    failureCallback:
    
                                    {
    
                                       fn: function(response)
    
                                       {
    
                                                      // Display error message and reload
    
                                                      Alfresco.util.PopupManager.displayPrompt(
    
                                                      {
    
                                                                     title: Alfresco.util.message("message.failure", this.name),
    
                                                                     text: "search failed"
    
                                                      });                                          
    
                                       },
    
                                       scope: this
    
                                    }
    
    });
    
    },
    

    pass your data to dataObj like dataObj:data

    and create post webscript and you can get your post parameters in your server side/data/repo webscripts like this

    var param1 = json.get("noderef");

    and do what you wanted to do .