BookmarkSubscribeRSS Feed
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){

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.



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'


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.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2 in conversation