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

Re: Read body in XSJS

$
0
0

Chad,

 

I see a few things here :

1) do not include $ to get the parameter

2) your response type - use html if you are returning a valid html response, otherwise I suggest to respond with json as you are sending json into your xsjs service

 

here is a modified version of your code - hope it works (for some reason I couldn't format it) but you can on your side

 

 

function updateData() { var body = { response : ''};         if ($.request.parameters.get("mode") === "ins") {      var sData = $.request.body.asString();      var oJson = JSON.parse(sData);      var squery = 'INSERT INTO "SYSTEM"."bootcamp.DB::JobModel.Job" VALUES (?,?,?,?,?,?)';      var connection = $.hdb.getConnection();      connection.executeUpdate(squery,oJson.JOBID,oJson.DESCRIPTION,oJson.DEPARTMENT,oJson.VALID_TILL,'','');      connection.commit();      connection.close();           body.response = "Success";          } else {       body.response = "Wrong Mode!";   }      $.response.setBody(JSON.stringify(response));   $.response.status = $.net.http.OK;   $.response.contentType = ""application/json"";  // I would recomment to return json and use the "application/json" as the content type, otherwise you need to set valid html to use html type response }  updateData();


Viewing all articles
Browse latest Browse all 974

Trending Articles



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