BookmarkSubscribeRSS Feed
TedP
Obsidian | Level 7

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){
	  	alert(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.

 

 

2 REPLIES 2
TedP
Obsidian | Level 7

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'

  

boemskats
Lapis Lazuli | Level 10

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.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1863 views
  • 0 likes
  • 2 in conversation