How to receive special character?

Submitting raw input with a plus sign via HTTP GET will cause the plus sign to not be sent. It is a reserved character. See here.

Your old code built the GET request by hand like so:

var code = "code=" + code;
$.ajax({
  // ...
  data: code,
  /// ...
});

But you never used encodeURIComponent(code), thus causing your plus signs to be lost to the gaping jaws of the specification.

var code = "code=" + encodeURIComponent(code);

jQuery will do this automatically though if you pass it a plain object. Building urls is annoying, so this is the pattern I prefer:

$.ajax({
  // ...
  data: {
    code: code
  },
  /// ...
});

Leave a Comment