0

I am making a bookmarklet that uses $.getJSON() to transfer data from browser (different domain) to server and back. and I am having several issues with url encoding.

When I send the data to php I use encodeURIComponent() and decodeURIComponent() the response. in the php i do no encoding or decoding.

In many situation this works fine in cases of "/ & etc.

However if i have ',' or % or some other character, when i get the response and it tries to decodeURIComponent. i get the following error :URIError: malformed URI sequence

Is there a better way to encode url ?

Thanks

Neta Meta
  • 4,001
  • 9
  • 42
  • 67
  • 1
    was all `,` doesn't been converted into `%2C` – Netorica Jan 21 '14 at 03:19
  • that's really weird. in some places it works in others i doesnt. in some languges it does in others it doesnt – Neta Meta Jan 21 '14 at 03:27
  • its really best to encode your URL using PHP because if you let javascript encode it for you it different kinds of browsers `decodeURIcomponent` maybe behaves differently – Netorica Jan 21 '14 at 03:31
  • And how will i decode it afterward in the JS ? + will php be able to pick up the un-encoded url ? – Neta Meta Jan 21 '14 at 03:34
  • I've gone through the code again and found out that i was encoding both in JS and in php, but decoding just in JS, so fixing this fixed most of the issues except quotes " instead of decoding it its writes :" – Neta Meta Jan 21 '14 at 03:51
  • I know this is a very dirty trick but if its only ',' is being the problem, why not replace is with the right encoding using string functions? – Netorica Jan 21 '14 at 04:00
  • seems http://stackoverflow.com/questions/1147359/how-to-decode-html-entities-using-jquery fixed the issues – Neta Meta Jan 21 '14 at 04:02
  • well its really unsafe... I think... – Netorica Jan 21 '14 at 04:03
  • Check the above solution provided in that question ,its dreamy . fixed everything ! – Neta Meta Jan 21 '14 at 04:04

0 Answers0