4

how do i encode the keyword that get sent to the server and then decode it?

I can't search for keywords containing chars like .? or / at the moment.

The code displaying is wrong because endpoint returns a object.

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

If i use encodeURIComponent() my url is encoded but my controller isn't hit:

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 Answers 2

1

You can use the escape function: http://www.w3schools.com/jsref/jsref_escape.asp

Sign up to request clarification or add additional context in comments.

4 Comments

The escape() function was deprecated in JavaScript version 1.5. Use encodeURI() or encodeURIComponent() instead. But doesen't angular have something for this?
When i use encodeURIComponent() it encodes the string but console outputs a 404. My controllers breakpoint isent hit. Updates my question.
Why would he need one if this methods do the job?
Why you get 404 is hard to answer without seeing anything from your server side configuration. If you try constructing the request with something like chrome.google.com/webstore/detail/advanced-rest-client/…, do you also get 404?
0

Ended up making a query string instead:

var endpoint = baseEndpoint + "search?keyword=" + keyword,

1 Comment

I think it's more suitable anyway. It's more RESTFUL to use path variables only when they serve as coordinates for the requested resources.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.