ajax - How to escape & and % in a POST request in jQuery?
posted on: 16:29, May 28th , 2014I have input element like that
<input type="checkbox" value="rock&pop" />
When i try sending it through an ajax request:
$.ajax({
type: "POST",
url: "/add.php",
data: "id="+id+"&value="+value+"&type="+type,
error: function(){alert(error...');}
});
Nothing gets sent and the script breaks.
the solution:
You can set your data option as an object and let jQuery do the encoding, like this:
data: { id: id, value: value, type: type },
Now specil chars are escaped like they should.
Comments:
All materials on this site are licensed under the following license: "Steal every piece of information you can get your hands on and run as fast as you can "