angular encode url搜索字符串

时间:2014-07-06 13:42:36

标签: angularjs url-encoding

如何编码发送到服务器然后解码的关键字?

我无法搜索包含字符的关键字。或/ /此刻。

代码显示错误,因为端点返回一个对象。

 self.search = function (keyword) {
            var endpoint = $location.path(baseEndpoint + "search/").search(keyword),
                deferred = $q.defer();

            $http.get(HttpRequestUrlHelper.ensureUniqueRequestUrl(endpoint), {
            }).success(function (response) {
                deferred.resolve(response);
            }).error(function (error) {
                deferred.reject(error);
            });

            return deferred.promise;
        }

如果我使用encodeURIComponent(),我的网址会被编码,但我的控制器没有被点击:

request url => /todo/search/Leka%20med%20barnen.?UniqueKey=1404655031784 angular.js:9159
GET http://localhost:49195/todo/search/Leka%20med%20barnen.?UniqueKey=1404655031784 404 (Not Found) 

2 个答案:

答案 0 :(得分:1)

您可以使用转义功能:http://www.w3schools.com/jsref/jsref_escape.asp

答案 1 :(得分:0)

改为创建查询字符串:

var endpoint = baseEndpoint + "search?keyword=" + keyword,
相关问题