Reputation: 846
I have a html text in js cookie. When i tried to get the text in cookie and set that text in a html div, it becomes encoded. I tried to decode the html but no use.
This is my code:
function addToCoupon(team1,team2,id,bet,rate){
var betTableContent=$('#bet_table').html();
var row="<tr><td>"+team1+"-"+team2+"</td><td>"+bet+"</td><td>"+rate+"</td></tr>";
betTableContent+=row;
$.cookie("coupon",betTableContent);
$('#bet_table').html(unescape($.cookie("coupon")));
}
My text in #bet_table looks as not matter if I use unescape() function or not:
%3Ctr%3E%3Ctd%3EHapoel%20Nazareth%20Elite-Maccabi%20Herzliya%3C%2Ftd%3E%3Ctd%3E1X2
So how can I display this html text as normal html?
Upvotes: 0
Views: 39
Reputation: 7244
Just escape it before you create it and then unescape it like this
jQuery.cookie('coupon', escape('<html></html>'));
console.log(unescape(jQuery.cookie('coupon')));
Upvotes: 3