i have wriiten a jquery ajax code of posing comment..
function PostComment()
{
$.ajax({
type :"POST",
url:PageUrl+'Post_LectureComment',
data:"{Comment:'"+$('#txt_PostComment').val()+"',LectureID:'"+87+"',CategoryID:'"+2+"',Author_Id:'"+ 78+"' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success:SuccessHandler ,
});
function SuccessHandler(data)
{}
}
when i am sending data in txt_PostComment with ' like =durgesh'rao it is showing error
Request Payload: {Comment: 'durgesh'rao',LectureID:'1250',CategoryID:'2',Author_Id:'135' }
is any way to send data with ' ???
I believe you r trying to build JSON object that contain the '
character. So to solve the this problem you need first to handle the strings with '
function replacequote(text) {
var newText = "";
for (var i = 0; i < text.length; i++) {
if (text[i] == "'") {
newText += "\\'";
}
else
newText += text[i];
}
return newText;
};
function PostComment()
{
$.ajax({
type :"POST",
url:PageUrl+'Post_LectureComment',
data:"{Comment:'" + replacequote($('#txt_PostComment').val()) + "',LectureID:'"+87+"',CategoryID:'"+2+"',Author_Id:'"+ 78+"' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success:SuccessHandler ,
});
function SuccessHandler(data)
{}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With