Getting POST parameters for a JavaScript webscript
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2011 04:17 PM
For webscripts written in JavaScript, I'm able to get parameters in the query string via the "args" object. However, after looking over the object list in Chapter 9 of "Professional Alfresco", looking through the wiki, playing around a bit, and searching the web, I seem to be unable to find a way to get POST parameters (parameters passed in the HTTP message's body). Is there a way to access these parameters from a webscript?
As an example, here is how I'm passing the variables to the webscript from client side (this is for a Share dashlet that's talking to the repository):
As an example, here is how I'm passing the variables to the webscript from client side (this is for a Share dashlet that's talking to the repository):
var sUrl = Alfresco.constants.PROXY_URI + "folder-search";var postData = "searchTxt=" + document.getElementById("jtf_text").value;var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
Labels:
- Labels:
-
Archive
3 REPLIES 3

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2011 09:23 AM
Hi,
I know it's a bit late but… Have you tried using the requestBody object?
As in requestbody.content
Check this page http://wiki.alfresco.com/wiki/Web_Scripts#Request_Processing
Hope that helps.
I know it's a bit late but… Have you tried using the requestBody object?
As in requestbody.content
Check this page http://wiki.alfresco.com/wiki/Web_Scripts#Request_Processing
Hope that helps.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2011 09:40 AM
In order to use args, you must post a formdata. This can be done either with a form or with:
but formdata object is not supported by ie (don't remember which versions) so there are some more obscure ways:
http://mike.kaply.com/2010/05/20/post-multipart-form-xhr/ (I don't fully understand how it works but I know it does)
function getXhr(){ var xhr = null; if(window.XMLHttpRequest) xhr = new XMLHttpRequest(); else if(window.ActiveXObject){ try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } } else { alert("${message('templates.apmSearch.get.error.XMLHTTP')}"); xhr = false; } return xhr;}var url = Alfresco.constants.PROXY_URI + "folder-search";var xhr = getXhr();xhr.open("POST",url,false);var data = new FormData();data.append("searchTxt", document.getElementById("jtf_text").value);xhr.send(data);
but formdata object is not supported by ie (don't remember which versions) so there are some more obscure ways:
http://mike.kaply.com/2010/05/20/post-multipart-form-xhr/ (I don't fully understand how it works but I know it does)

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2011 04:36 AM
Or you can POST that as a json. Ie. from Share (or wherever) use the YUI ajax request:
Then you can get the json object in your webscript, like this:
Alfresco.util.Ajax.request({ url: webscriptUrl, method: POST, requestContentType: "application/json", … // other params
Then you can get the json object in your webscript, like this:
var param1 = json.get("param1");
