0

I am stuck with a problem. For instance if i have a json Object parameter like param = {abc: 'my example parameter'} and have an api like var api = 'api/xyz?'

now I want to append the parameters to my api, so I am using the following line of code

var url = api + Ember.$.param(param || {});

but the problem with this method is that when I use Ember.$.param(param || {}) and if the param contains spaces it results in as url = 'api/xyz?abc=my+example+parameter' instead of var url = 'api/xyz?abc=my example parameter'

I know I can always right a custom function for this but I want to do it using the Ember's inbuilt functionalities, so is there any such Emberish way in which I can get the required api call without '+' in the parameter for spaces.

locks
  • 6,537
  • 32
  • 39
Sumit Surana
  • 1,554
  • 2
  • 14
  • 28
  • 1
    [urls shouldn't contain spaces](http://stackoverflow.com/questions/5442658/spaces-in-urls), so [jQuery.param](http://api.jquery.com/jquery.param/) is encoding it correctly. Either `+` or `%20` turns into a space, when the server decodes it – James Oct 29 '15 at 06:28
  • converting it into %20 is good enough but here the situation is it is converting it into +, and i don't want it to convert it into '+' – Sumit Surana Oct 29 '15 at 07:08
  • 2
    Why not? Aren't you making a url? `+` = space. If it really matters, `Ember.$.param(param || {}).replace('+','%20')`; – James Oct 29 '15 at 07:43
  • but this would replace even '+' sign that incase I want to pass in the url. – Sumit Surana Oct 30 '15 at 04:05
  • You obviously haven't tried it, because `+` gets encoded to `%2B` – James Oct 30 '15 at 06:20

0 Answers0