Reputation: 10192
there is a textarea on the page. and i am sending its value via ajax.
var text = $("textarea#text").val();
var dataString = 'text='+ text;
$.ajax({
type: "POST",
url: "do.php?act=save",
data: dataString,
cahce: false,
success: function() {
//success
}
});
if textarea value is sth like that black & white
, it breaks text after the black
if it is sth like that black + white
it outputs like black white
how can i avoid this?
thx
Upvotes: 0
Views: 1971
Reputation: 1
you can achieve this by using JSON object
eg: [{"AttributeId":"4035","Value":"Street & House"}]
or you can use URLencode before post
Upvotes: 0
Reputation: 25820
Or JSON.stringify which converts a JSON object to string representation.
Upvotes: 0
Reputation: 827922
You need to encode the text, but I think is better to use an Object rather than a String as the data
member, jQuery will do the job of properly encoding the POST/GET parameters:
var text = $("textarea#text").val();
var dataObj = {"text": text};
$.ajax({
type: "POST",
url: "do.php?act=save",
data: dataObj,
cache: false,
success: function() {
//success
}
});
Upvotes: 1