Your SAS programs, embedded in web apps and elsewhere

AJAX POST data not available in Stored Process

Posts: 33

AJAX POST data not available in Stored Process

This mostly a duplicate question that went unanswered. GET requests work fine and var1 and var2 both become SAS variables in the receiving stored process, but POST requests are failing. Here is the sample request that works. Change it to a POST and it fails.


$.ajax({url: '&_THISSESSION&' + '_program=/my_stored_process', 
	type: 'GET',
   	data: { var1: 1, var2: 'somevalue'} ,
	contentType: 'application/json; charset=utf-8',
	success: function(result){

It seems the answer (which was mentioned in the previous thread) is to create a data source and send the stored process properly formatted XML which is painful. But, was wondering if anyone else found a way to get a POST to work. 


And I've actually answered this myself extremely painfully here. Just wondering if this is the only way.



Posts: 33

Re: AJAX POST data not available in Stored Process

[ Edited ]

Turns out the data line string in the jquery ajax needs to be formatted differently and quite annoyingly the content type needs to be modified as well.


data : 'var1=1234&var2=othername'
contentType : 'application/x-www-form-urlencoded'


Frequent Contributor
Posts: 91

Re: AJAX POST data not available in Stored Process

The way JQuery handles POST data is a little annoying compared to most other frameworks. It doesn't really do anything with the data you pass it for a POST, expecting you to preformat and urlencode your post body yourself so that it can just append to the request. For GET requests it serialises and encodes the data properly.


There's a little more info on the content-type subject in this post (not sure if you've seen my reply as I wrote it about 5 months after your question). It is somewhat specific to POST requests - simplest explanation I've found is on wikipedia. From the best of my knowledge, it's all to do with the old days when POST requests were used to submit form data, and x-form-www-urlencoded being the only type that allows you send duplicate parameter values (ie. how multiselects were handled in old school forms). SAS expects this contentType and takes advantage of the duplicate params capability with the whole &parameter=firstvalue, &parameter0=2, &parameter1=firstvalue, &parameter2=secondvalue approach. Conversely, multipart/form-data is what you'd use for uploading files, which is very well documented by SAS here, (I assume you know about it but others might not).


To see how our adapter handles this, see here and here.

Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation