2016-09-30 78 views
1

我得到的服務,使ajax調用(GET)。angularjs - url獲取在ajax調用編碼

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

當我打這個電話時,url得到這樣的編碼。 http://localhost:8080/api/meme_%E2%80%8Bvalues?category_id=MLB1468&%E2%80%8Battribute_id=MLB1234

我該如何解決這個問題?我試着用的toString(),decodeURIComponent轉換,但沒有奏效

回答

1

有一個控制字符(LRM)在字符串中

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

meme_attribute_id=之前只是刪除它,你會沒事的。
這個角色通常來自ms word這樣的編輯。

+0

謝謝,就是這樣。 –

0

encodeURIComponent可能是你在找什麼:

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

編輯:decodeURIComponent是完全相反,試圖解碼一個URI編碼的字符串。

1

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); 
 
};