uksz uksz - 6 months ago 30
Javascript Question

JQuery param escaping & sign

I have the following object:

var ob = {
prop: 'ab&cs&ef'
}


When I use param method from jQuery ($.param()), it returns:

"prop=ab%26cs%26ef"


How can I make it return the following?

"prop=ab&cs&ef"


Update

I know, that if I use:

unescape($.param(ob))


I will receive what I need. However, unescape method is deprecated.

Answer

You have to decode the URI coded result again p.e. like this:

var ob = {
  prop: 'ab&cs&ef'
}
alert(decodeURIComponent($.param(ob)));