I am developing one website where i insert data through ajax in Json format to php page then after decoding it send to mysql database,but if my string contains < > || & ' "
characters then my web page gives php error.so how should i proceed further. It doesn't allow for inserting some special characters ..
var obj = {"comment": commentText, "postID": postID};
var commentData = 'commentData=' + JSON.stringify(obj);
$.ajax({
type: "POST",
url: addNewCommentsUrl,
datatype: 'json',
data: commentData,
cache: false,
beforeSend: function() {
// $(document.body).off('click','.postComment');
},
success: function(result) {
commentBox.val("");
commentHolder.append(result);
// jQuery("#all-posts").masonry('reloadItems');
jQuery('#all-posts').masonry('layout');
var count = parseInt(parent.find("#commentContainer").text());
parent.find("#commentContainer").html(++count);
// $(document.body).on('click','.postComment');
}
});// end of ajax
at php side
$recievedData = $_POST['commentData'];
$recieveddatajson = json_decode($recievedData);
$lastCommentID = $recieveddatajson->{'commentID'};
$parentPostID = $recieveddatajson->{'postID'};