Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3353

Processing HTTP POST request on HANA xsjs

$
0
0

Hi,

 

     I would like to know how to handle a HTTP POST request in an XSJS file.I have a form with many input fields and I would like call an HANA xsjs file to process the data after user clicks on a submit button.

     In case of a HTTP GET method, one can append the values of the form parameters as query strings and pass it in the URL.such as below.

            /path/<name of the xsjs>.xsjs?param1=val1&param2=val2.

     on the server side,the values can be retrived as,

         var sel_param1 = $.request.parameters.get("param1");

 

     Now,since  have to pass the values thru HTTP POST,I referred to the below thread

 

        http://scn.sap.com/thread/3557509  In this method,it is explained how to to pass the parameters in HTTP Post. For this, a javascript object is created and sent via $.ajax method as below.

 

 

<script type="text/javascript">

     function callService(){

  var oBusinessPartner  = {};

  oBusinessPartner.PARTNERID = "0000000000";

  oBusinessPartner.EMAILADDRESS = "test@sap.com";

 

  $.ajax({

                 url: '/playground/test/post.xsjs?ACTION=ADD_PROJECT',

                 type: 'POST',

                 contentType: 'application/json',

                 data: JSON.stringify(oBusinessPartner),

                 dataType: 'json',

                 success: function(){alert("Success")},

                 error:  function(jqXHR, textStatus, errorThrown){

                     sap.ui.commons.MessageBox.show(jqXHR.responseText, "ERROR", "Service call error");

                 }

             });

 

     }

 

 

On XSJS side,the the the value is retrived as below,

 

          var content = $.request.body.asString();

 

 

My question is,how to obtain the individual parameter values such as PARTNERID,EMAILADDRESS from the variable content.

 

Regards

Veera


Viewing all articles
Browse latest Browse all 3353

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>