Possible Duplicate:
How to escape & in a POST request in jQuery?
I am using the jQuery ajax to do auto complete on my website. I am running into a problem though, an & can be stored in the database and that just wreaks havoc with my posted variables.
What it needs to do: ajax=true&search=t&w (With the ampersand and w part of the search variable)
What it does though is it creates a new post variable of w.
Is there a way to block the ampersand from creating a new post variable, or do I just need to change the &'s to and/And
Here is my code:
$.ajax({
url: page_url,
type: 'POST',
data: 'ajax=true&search='+$('#search_string').val(),
success: function(data){
}
});
If the values are encoded, how will the database handle the encoded &?
If you set the value passed to data as an object it will painlessly encode:
see: How to escape & in a POST request in jQuery?