Search code examples
javascriptjqueryjsonbing-api

Getting rid of strange code


I have a script over here: JsFiddle

If you scroll down in the javascript at some point you will see function urlencode (str) { So from this on till the bottom is a piece of code I don't understand. I have never seen such coding and I also dont know why this is in the script. It seems that deleting this is not an option since the script will not work without. So I actually have two questions:

1.Why is this in the script?

2.How do I get rid of it to shorten my code?


Solution

  • 1. The script is there to encode special characters as Hex so they can be safely transmitted as plain text without being corrupted en-route

    2. Don't get rid of it. If you want to shorten it, take all the comments out :) You could also whizz it through a minifier...

    You could look online for shorter JavaScript URLEncode routines, or see if you are already using an existing library which provides such functionality. However I would stick with the one you've got as it may do something specific to your application.