1

A quick question

Does php function json_encode or js JSON.parse function drops '+' character by default? I definitely get a '+' lost somewhere and at cannot figure out where. This is quite urgent as it's actually an xml feed from realex, which authorizes (or in this case doesn't authorize) payments on one of our live sites. To make things more complex, I cannot use dev environment at the moment and I cannot play in printing out values on the screen on the live site. So I'm trying to make a guessed-fix for the start

Ok, here's some exmaple

I get a value from Realex

   $RESPONSE_THREEDSECURE_CAVV = 'jFvMUENpUEzLARAQBtmeh+Q5o/U=';
   $parametersToPass['cavv'] = $RESPONSE_THREEDSECURE_CAVV;

There are more values in parametersToPass array, but this is the one that's causing troubles. I encode it in php

   $encoded = json_encode($parametersToPass);
   die($encoded);

This is being returned in jquery ajax call success as 'data'

 success: function(data) {
    $.ajax({ 
      type: "POST",
      url: 'action/payment-process_auth.php',
      data: "data="+data
    });
  }

I retieve it in payment-process-auth

 $decoded = json_decode($_POST['data']);
 $parametersToPass['cavv'] = $decoded->cavv;

At this point cavv value is jFvMUENpUEzLARAQBtmeh Q5o/U= instead of jFvMUENpUEzLARAQBtmeh+Q5o/U= (space instead of a +)

How can I sort this out?

3
  • 2
    What do you mean by "drop"? Where is it? Commented Apr 3, 2012 at 15:33
  • 2
    You need to provide us some json samples that demonstrate the problem. Commented Apr 3, 2012 at 15:33
  • is the + character part of a string ? can you share the JSON ? Commented Apr 3, 2012 at 15:34

2 Answers 2

4

No, json_decode and JSON.parse both respect + characters.

In a URL, though, a + is turned into a space if not properly urlencoded to %2B... so if you're json_decodeing a $_GET parameter that may be what's going on.

Sign up to request clarification or add additional context in comments.

Comments

1

Try posting your data with AJAX in a proper JSON format?

success: function(data) {
$.ajax({ 
  type: "POST",
  url: 'action/payment-process_auth.php',
  data: {"data": data}
});

}

1 Comment

Looks like this may have sorted it. I missed the fact that such data passing is not json format. Would like to have a link to an online example I took it from. I still need to confirm id this is fixed, will give you a V if it's fine, thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.