Skip to Content
avatar image
Former Member

POST call for jQuery AJAX call

Hi Experts,

I am making a POST call to xsjs service. I am not sure what is going wrong at the controller end, that I m unable to read the response.
When I open the service independently in a browser I can see the data but, through UI it gives an error Error 403 - Forbidden.
Could you please suggest where am I going wrong. Is it the XSJS service or in controller.
Appreciate your guidance on this.

XSJS-

var conn = $.hdb.getConnection();

var query,results;

try{

query = "select distinct CUST_NO,NAME,CNTRY_CODE from SCHEMA.TABLE_NAME ";

results = conn.executeQuery(query);

conn.commit();

var output = [[]];

for (var i = 0; i< results.length; i++)

{

output.push(results[i]);

}

output.shift();

conn.close();

$.response.setBody(JSON.stringify(output));

$.response.contentType = 'application/json';

$.response.status = $.net.http.OK; }

catch (e) {

$.response.status = $.net.http.INTERNAL_SERVER_ERROR; $.response.setBody(e.message);

}

AJAX call in CONTROLLER -

jQuery.ajax({

type : 'POST',

contentType: 'application/json',

url: "/z_demo1/services/cmsCurr.xsjs?action=Customer",

cache: false,

async : false,

beforeSend : function(jqXHR1,settings) {

jqXHR1.setRequestHeader('X-CSRF-Token',jqXHR1.getResponseHeader('X-CSRF-Token')); },

success: function(odata,response) {

alert("hi");

},

error: function(jqXHR1, textStatus, errorThrown) { alert(jqXHR1.responseText); }, dataType: "json"

}, this);

Thanks,

Supriya Sahu

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Sep 20, 2017 at 01:30 PM

    Hi Supriya,

    You can get the 403 - forbidden error when there is a problem in validating X-CSRF-Token from backend. Please check below thread:

    https://archive.sap.com/discussions/thread/3804252

    Add comment
    10|10000 characters needed characters exceeded