开发者

Posting data ajax jquery, html data

开发者 https://www.devze.com 2023-01-14 01:09 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号