0

I am creating a search bar which get projects from API and shows them all are works fine but when I search for # or any character followed by # in the search bar nothing returned not "project not found" functionality also. It shows only current page.I am using AngularJS 1.2

Animay
  • 602
  • 1
  • 7
  • 18

1 Answers1

1

The reason being you have to encode the special characters before sending it to the server. You can use encodeURIComponent() javascript method.

NOTE: encodeURIComponent() will not encode: ~!*()'

To encode the above characters as well, use a custom method.

customEncodeURIComponent = function (tURL) {
      return encodeURIComponent(tURL).replace(/[!'()]/g, escape); 
};

Reference link

Gowthaman
  • 1,262
  • 1
  • 9
  • 15
  • `escape` method does not encode `@*_+-./` and encodeURIComponent does not encode `~!*()'` . Which means the custom method will not encode `*_-.` You have to include that in the custom method `.replace(/[!'()]/g, escape).replace(/\*/g, "%2A")` This will encode `*`. Refer to this [list](https://www.w3schools.com/tags/ref_urlencode.asp) for other values. – Gowthaman Apr 12 '18 at 14:35
  • I have encoded but Underscore and percentage characters are not working, may be back-end problem – Animay Apr 13 '18 at 10:32