why JSON doesn't work with html text (var text_html = '<p></p><t></t>
'; ) but this will be work correct (var text_html = 'example';)
doesn't work
var text_html = JSON.parse('<p></p><t></t>');
Problem:
function Save() { var text_html = '<p></p><t></t>'; $.ajax({ url: '@Url.Action("DodajTematSave", "StronaGlowna")', dataType: "json", data: { My_Text: text_html }, type: "POST", async: false, error: function () { }, success: function (data) { if (data.Success) { alert('success'); } } }); } </script> public JsonResult DodajTematSave(string My_Text) { return Json(new { Success = true}); }
also this doesn`t work
var dom_string = '<div>xxx<div>yyy</div></div>'; var text_html = dom_string.innerText();
also this doesn`t work
<script type="text/javascript"> function Save() { var Temat_controll = $('#Temat').val(); var Streszczenie_controll = $.parseJSON('<p></p><t></t>'); var PelnyOpis_controll = $('#PelnyOpis').text(); $.ajaxSetup({ contentType: "application/json; charset=utf-8", dataType: "json" }); $.ajax({ url: '@Url.Action("DodajTematSave", "StronaGlowna")', dataType: "json", data: { Temat: Temat_controll, Streszczenie: Streszczenie_controll, PelnyOpis: PelnyOpis_controll }, type: "POST", async: false, error: function () { }, success: function (data) { if (data.Success) { alert('success'); } } }); } </script>