Ajax收到消息问题

I'm sending some message through Ajax, using encodeURIComponent but in the server side I getting some unwanted character in the message for example instead of the

can't

I'm getting

can\'t

What is the solution for this problem

Try this answer:

<?php 
// first use encodeURIComponent on javascript to encode the string 
// receive json string and prepare it to json_decode 
$jsonStr = stripslashes ($_POST['action']); 
// decode to php object 
$json = json_decode ($jsonStr); 

// $json is now a php object 
?>

Given from:

http://php.net/manual/en/function.urldecode.php

There's a chance that the framework you're using is proactively trying to prevent SQL Injection attacks by escaping the single-quote character by default. Look into the documentation for your framework for a way to get the verbatim text from the POST data.

Quotes do not get escaped by encodeURIComponent. namuol is correct, your framework is trying to be very smart for you and applying its own escaping to everything passed through POST and GET. If using PHP, make sure Magic quotes is turned off, it's now deprecated.