I am using Jquerys ajax function to post data to my database. I have a textarea that allows users to type in their posts and update it to the database.
Here is a code snippet:
$.ajax({
type : "POST",
url: "process.php",
data: "postmessage="+ postmessage +"& from_user="+ from_user +"& from_username="+ from_username,
My problem is that when the data 开发者_运维问答within the 'postmessage' variable contains character such as " and ' it fails to post. How can I turn filter these characters and put them back in on the other end????
Example text:
"I've been talking alot lately"
Never concatenate strings. You could pass the arguments as a hash:
$.ajax({
type : 'POST',
url: 'process.php',
data: { postmessage: postmessage,
from_user: from_user,
from_username: from_username },
success: function(result) {
}
});
This way jQuery will take care of properly URL encoding parameters.
精彩评论