0

I am newbie in javascript and need some help :( I am simply using post api in my html page like this

varsettings = {
  "url": "https://credimax.gateway.mastercard.com/api/nvp/version/54",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded",
    "Cookie": "TS01f8f5b8=0163461fdde5ee3588241a8b83c8806a36a236cc1484715206aeee58f05ff4acc21bff27c0f22f45d8027bdfa3ef1b330efc711746"
  },
  "data": {
    "apiOperation": "CREATE_CHECKOUT_SESSION",
    "apiPassword": "asdasdasdsad",
    "apiUsername": "merchant.sadasda",
    "merchant": "asdasda",
    "interaction.operation": "AUTHORIZE",
    "order.id": "121312327",
    "order.amount": "0.01",
    "order.currency": "BHD"
  }



};
$.ajax(varsettings).done(function(response) {
  console.log(response);


});

                 

Its showing responsei n console correctly like this

merchant=E10561950&result=SUCCESS&session.id=SESSION0002247374303I6654970F90&session.updateStatus=SUCCESS&session.version=18a5ad4401&successIndicator=5f04c5071d2f46fd

I want to just console the session.id from response how can i do this ?

i try with with console.log(response.session.id) but its not showing

1

2 Answers 2

1

Please try this:

<script>
    $.ajax(varsettings).done(function (response) {
        let items = response.split('&');
        let sessionIDText = items[2];
        let sessionIDParts = sessionIDText.split('=');
        let sessionID = sessionIDParts[1]
        console.log(sessionID);
    });
</script>

or simply :

    sessionID = response.split('&')[2].split('=')[1];

0
0

You have received a string back from the server that needs to be decoded into an object before you can work with it. Try obj = decodeURIComponent(response) and see if you can work with the resulting obj

2
  • i try and then console obj its same hot show session.id from this obj ?
    – umaiz khan
    Commented Jan 5, 2021 at 14:10
  • maybe try just decodeURI(result) ...sorry I am on a phone and can't test right now but look at this thread... stackoverflow.com/questions/9692071/…
    – joshstrike
    Commented Jan 5, 2021 at 14:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.