cancel
Showing results for 
Search instead for 
Did you mean: 

POST variables

alina
Champ in-the-making
Champ in-the-making
Hello!
I'm still building my first script. Smiley Happy
The problem now is - how can I get POST vars in the js file?

I use ajax on my side - so I cannot send 'multipart/form-data' and access it through 'formdata' object.
For GET vars there is 'url.extension', but for POST??
I send JSON data, but json is undefined.
6 REPLIES 6

jonash
Champ in-the-making
Champ in-the-making
Hi,

You can use the "requestbody" object to access the request body that was sent with the POST request.  To get the "json" object you have to name the javascript controller of your webscript "<name>.post.json.js".

You can get more details on the wiki: http://wiki.alfresco.com/wiki/Web_Scripts#Request_Processing

alina
Champ in-the-making
Champ in-the-making
Thanks, but requestbody is empty anyway.

I have three files:
   
folder1.post.js
model.action = requestbody.size;

folder1.post.json.ftl
${action}

and folder1.post.desc.xml
<webscript>
  <shortname>Blah-blah</shortname>
  <description>Blah-blah and so on</description>
  <url>/test/folder1</url>
  <format default="json">argument</format>
  <authentication>admin</authentication>
  <transaction>required</transaction>
</webscript>

No matter what I give in, I get requestbody.size = -1. How could that be?

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
How are you doing the POST? I guess you are posting a JSON object with two fields? You can check your requests parameters, body, header, etc by using Firebug or the Developer's Tool of Chrome, so you know what you are sending is OK

alina
Champ in-the-making
Champ in-the-making
I sent a JSON object with five fields. I tried to send it like "data={'name': "jennifer",…..} or just the object itself.

Yes, I've checked request parameters, headers and body with Firebug and Fiddler, I also tried to send a primitive form (not json data, but a couple of text fields). Requestbody.size equals to -1.

scapeler
Champ in-the-making
Champ in-the-making
are you sure that json is undefined?
did you try something like : model.name=json.get('name');

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
It would be helpful to check what's the output of Firebug, so we can help you the right way, also you could post the bit of code that creates the request and the piece of code that receives/parses it…

Regards,
Adei