Reputation: 77
I have got this Ajax that send comment's text to PHP
$.ajax({
type: "GET",
url: '../files/ajax.php',
data: "C=" + cc+"&I="+i,
success:function(data) {
alert(data);
}
});
if (isset($_GET["I"]) && isset($_GET["C"])) {
$RandS=$_GET["I"];
$Comment=$_GET["C"];
$Comment=trim($_GET["C"]);
$Comment=htmlspecialchars($_GET["C"]);
echo $Comment;
}
When comment is something like
Hope you like pancakes
It returns everything perfectly,But when comment is '#I #Like pancakes'
it does not return anything except error
Uncaught SyntaxError: Unexpected end of JSON input
Upvotes: 3
Views: 51
Reputation: 781088
You need to URL-encode the parameters if they contain special characters. When using $.ajax
, the best way to ensure that they're encoded properly is to use an object rather than a string for the data:
option.
$.ajax({
type: "GET",
url: '../files/ajax.php',
data: { C: cc, I: i },
success:function(data) {
alert(data);
}
});
Upvotes: 2