0

I need to pass the '+' character with ajax parameter to my controller.

Ajax Call with parameter contain '+' charactor.

var subsNumbers = '+94'
var url = 'getList?subsNums='+subsNumbers;

$.ajax({
        url:url,
        type:'POST',
        dataType:'json',
        success:function (saveResponse) {
....
}
});

In my controller(Spring controller class),

String deviceNumbers = request.getParameter("subsNums");
logger.debug("deviceNumbers-->{}", deviceNumbers);

the '+' character has been replaced with space. Actual result is

deviceNumbers--> 94 

Expected is

deviceNumbers-->+94 
3
  • your ajax dataType is JSON but your sending a string right? and for your question I guess it can be solved by Url Encode @Client and Url Decode @Server. Commented Jan 2, 2014 at 11:38
  • @Yashhy stackoverflow.com/questions/13735869/… Commented Jan 2, 2014 at 11:41
  • @Musa thanks that was well explained!! :) Commented Jan 2, 2014 at 11:52

1 Answer 1

6

Your url is not properly encoded, use encodeURIComponent

var url = 'getList?subsNums='+encodeURIComponent(subsNumbers);
Sign up to request clarification or add additional context in comments.

1 Comment

to explain why: the + character in a URL is by convention a substitute for the illegal space character, so if your URL contains + symbols, the receiver MUST interpret them as "these are really spaces".

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.