Franco Manzur
Franco Manzur

Reputation: 373

angularjs - url get encoded in ajax call

i got service which makes an ajax call (GET).

var _getMemeValues = function(category_id, attribute_id) {
    return $http.get('/api/meme_​values?category_id='+category_id +'&​attribute_id='+attribute_id);
};

When i make that call the url get encoded like this. http://localhost:8080/api/meme_%E2%80%8Bvalues?category_id=MLB1468&%E2%80%8Battribute_id=MLB1234

How can i solve this? I Tried converting it with toString(), decodeURIComponent but it didn't work

Upvotes: 1

Views: 36

Answers (3)

Kerisnarendra
Kerisnarendra

Reputation: 913

It seems you should refactor the api or services to use the standard format like this:

'/api/meme_category_id/' + category_id + '/​meme_attribute_id/' + attribute_id

or to be more standard:
'/api/category/' + category_id + '/​attribute/' + attribute_id

and then call as usual in angularjs

function getMeme(categoryId, attributeId) {
 return $http.get('http://localhost/api/category/' + categoryId + '/attribute/' + attributeId);
};

Upvotes: 1

Musa
Musa

Reputation: 97672

There is a control character(LRM) in your string

'/api/meme_​values?category_id='+category_id +'&​attribute_id='
here       ^                         and here ^

i.e after meme_ and before attribute_id= just remove it and you'll be fine.
This character usually comes from editors like ms word.

Upvotes: 1

MattDiMu
MattDiMu

Reputation: 5013

encodeURIComponent is probably what you're looking for:

var someString = "Höe#äe sdfhlen3";
console.log("before: ", someString);
console.log("after : ", encodeURIComponent(someString))

edit: decodeURIComponent is exactly the opposite, trying to decode a URI-encoded string.

Upvotes: 0

Related Questions