Just use encodeURIComponent instead of encodeURI.
encodeURIComponent differ from encodeURI in that it encode reserved characters and Number sign #