0

In my project I have got a "back button" that is calling a javaScript function that remembers the previous url when called.

      //back button function 
        function goBack() { $window.history.back(); }

the url being remembered or being called when the back button is clicked contains an ID and this is ID is used to filter data. The main problem i'm having is that this ID is being returned as a string encoded in html. for example this is the url being called:

//Lookups?$filter=VehicleId%20eq%20%272415%27&

As you can see VehicleId is 2415 in above url, which is also encoded to %20%272415%27&. this in plain text is VehicleId = "2415". This is clashing with my program as my program is expecting an int variable instead of a string.

To resolve this i am trying to de -encode?? from html to make the ID to an int. and i having been looking at this http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_unescape but i still can't figure how to put this in my project.

I am using $location in order to remember the ID in url like so:

        if ($location.search().vehicle) {
                                var str = vehicle;
                                var strEsc = unescape(str);
                                vehicle = strEsc;

                              vehicle = $location.search().vehicle;

                            }

To be honest i don't if i am doing this right (which i'm not sure) ..Is any one to help with this please?

3
Contributors
2
Replies
29
Views
2 Years
Discussion Span
Last Post by Taywin
0

I used

a=unescape('Lookups?$filter=VehicleId%20eq%20%272415%27&');
alert(a);

and got back

Lookups?$filter=VehicleId eq '2415'&

Do you need more?

Edited by pritaeas: Fixed markdown (we do not use bbcode).

0

Simply use replace() function with regex. The returned value from window.history.back() is a string. You simply look up for ASCII table and use the "Hex" number. Then add the percentage symbol in the front - i.e. white space is %20. Therefore, your current string "VehicleId%20eq%20%272415%27&" should be "VehicleId eq '2415'&"...

var str = "VehicleId%20eq%20%272415%27&";
var decstr = str.replace(/%20/g, " ");
// decstr -> "VehicleId eq %272415%27&"
decstr = str.replace(/%27/g, "'");
// decstr -> "VehicleId eq '2415'&"

Edited by Taywin

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.