I am getting this error when i submit my form.
I get only when there is some ' or some character in it
<script type="text/javascript">
$(document).ready(function () {
$('.savedata').on("click", function () {
var converter = new showdown.Converter(),
text = $('#<%=messageBody.ClientID %>').val(),
html = converter.makeHtml(text);
if ($("#IsSchedule").is(":checked")) {
var isschedule = parseInt(1);
}
else {
var isschedule = parseInt(0);
}
$.ajax({
type: "POST",
url: "/Profile/StartDiscussion.aspx/updateData",
data: '{"DTitle":"' + $.trim($('#<%=TextBox1.ClientID %>').val()) + '","DMdContent":"/' + $('#<%=messageBody.ClientID %>').val() + '","DInvitedPeople":"' + $.trim($('#<%=InvitePeople.ClientID %>').val()) + '","DIsScheduled":"'+ isschedule + '","DScheduledDate":"' + $.trim($('#datetimescheduled').val()) + '","DCategory":"' + $.trim($("[id*='OptionsSelected'] :selected").text()) + '","DHtmlContent":"/' + html +'"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var obj = data.d;
if (obj == 'true') {
$('.postsubmit').css({ 'display': 'block' });
$('.postsubmit').delay(6000).fadeOut();
}
},
error: OnError
});
});
});
function OnError(xhr, errorType, exception) {
var responseText;
$("#dialog").html("");
try {
responseText = jQuery.parseJSON(xhr.responseText);
$("#dialog").append("<div><b>" + errorType + " " + exception + "</b></div>");
$("#dialog").append("<div><u>Exception</u>:<br /><br />" + responseText.ExceptionType + "</div>");
$("#dialog").append("<div><u>StackTrace</u>:<br /><br />" + responseText.StackTrace + "</div>");
$("#dialog").append("<div><u>Message</u>:<br /><br />" + responseText.Message + "</div>");
} catch (e) {
responseText = xhr.responseText;
$("#dialog").html(responseText);
}
$("#dialog").dialog({
title: "jQuery Exception Details",
width: 700,
buttons: {
Close: function () {
$(this).dialog('close');
}
}
});
}
$(document).ajaxStart(function () {
NProgress.start();
});
$(document).ajaxStop(function () {
NProgress.done();
});
</script>
[WebMethod]
[ScriptMethod]
public static string updateData(string DTitle, string DMdContent, string DInvitedPeople, int DIsScheduled, string DScheduledDate, string DCategory, string DHtmlContent)
{
String msg = String.Empty;
String decoded = Password.Decrypt(HttpContext.Current.Request.Cookies["UserEmail"].Value);
string conString = ConfigurationManager.ConnectionStrings["GitaAdmin"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("INSERT into DiscussionTable(DTitle, DMdContent, DActive , DApproved , DEmailSent , DStartedBy , DInvitedPeople , DIsScheduled , DScheduledDate, DCategory,DHtmlContent)"
+ "Values(@DTitle ,@DMdContent , @DActive , @DApproved , @DEmailSent , @DStartedBy , @DInvitedPeople , @DIsScheduled , @DScheduledDate,@DCategory,@DHtmlContent)"))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("@DTitle", DTitle);
cmd.Parameters.AddWithValue("@DMdContent", DMdContent);
cmd.Parameters.AddWithValue("@DActive", 0);
cmd.Parameters.AddWithValue("@DApproved", 0);
cmd.Parameters.AddWithValue("@DEmailSent", 0);
cmd.Parameters.AddWithValue("@dstartedby", decoded);
cmd.Parameters.AddWithValue("@DInvitedPeople", DInvitedPeople);
cmd.Parameters.AddWithValue("@DIsScheduled", DIsScheduled);
cmd.Parameters.AddWithValue("@DScheduledDate", DScheduledDate);
cmd.Parameters.AddWithValue("@DCategory", DCategory);
cmd.Parameters.AddWithValue("@DHtmlContent", DHtmlContent);
con.Open();
int rowsAffected = cmd.ExecuteNonQuery();
con.Close();
if (rowsAffected == 1)
{
msg = "true";
}
else
{
msg = "false";
}
}
}
return msg;
}