Alex Rivera | Logout

How to escape & in a POST request in jQuery?

Asked 2010-07-23T14:32:12.583
9

i have an input element with & in value:

<input type="checkbox" value="Biografie, životopisy, osudy, Domácí rock&amp;pop" />

When i try sending it through an ajax request:

$.ajax({
    type: "POST",
    url: "/admin/kategorie/add/link.json",
    data: "id="+id+"&value="+value+"&type="+type,
    error: function(){alert('Chyba! Reloadněte prosím stránku.');}
});

the post data that actually gets sent is:

id: 1
pop:
type: e
value: Biografie, životopisy, osudy, Domácí rock

*Note that all the variables in data are defined and value contains $(thatInputElement).attr('value').

How can I escape the &amp; properly so that post field value would contain Biografie, životopisy, osudy, Domácí rock&amp;pop?

Edit
Report

1 Answer

0

You could create an object and pass that along instead:

vars = new Object();
vars.id = id;
vars.value = value;
vars.type = type;

$.ajax({
  type: "POST",
  url: "/admin/kategorie/add/link.json",
  data: vars,
  error: function(){ alert('Chyba! Reloadněte prosím stránku.'); }
});
answered 2010-07-23T15:29:40.350

Your Answer