Ciao a tutti
Ho un problema con parole con singolo apice nel popolare un datatable jquery.
Il Datatable viene caricato in questo modo:
var TableManaged = function () {
return {
//main function to initiate the module
init: function () {
if (!jQuery().dataTable) {
return;
}
// begin table
oTable = $('#dtElenco').dataTable({
"oLanguage": {
"sUrl": "/Metronic/plugins/data-tables/language/it-IT.txt"
},
"aoColumns": [
{ "bSortable": false, "sClass": "txt-center" },
{ "bSortable": false, "sClass": "txt-center" },
null,
null,
{ "sClass": "txt-center" },
null,
{ "bSortable": false, "sClass": "txt-center" }
],
"aaSorting": [[2, "asc"]],
"aLengthMenu": [
[20, 50, 100],
[20, 50, 100] // change per page values here
],
// set the initial value
"iDisplayLength": 20,
"sPaginationType": "bootstrap",
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets': [0] },
{ "bSearchable": false, "aTargets": [0] }
],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/Handler/ajaxTable.ashx",
"fnServerData": function (sSource, aoData, fnCallback) {
aoData.push({ "name": "type", "value": "offerte" });
$.ajax({
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
"type": "GET",
"url": sSource,
"data": aoData,
"success": function (msg) {
var json = jQuery.parseJSON(msg);
fnCallback(json);
$("#dtElenco").show();
},
error: function (xhr, textStatus, error) {
}
});
},
});
}
};
}();
Per formattare i dati in formatto json corretto ho utilizzato sia
JavaScriptSerializer ser = new JavaScriptSerializer();
result = ser.Serialize(result);
sia
result = Json.Encode(result)
context.Response.ContentType = "application/json";
context.Response.Write(result);
Ma in entrambi i casi quando c'è per esempio "C'era una volta" ricevo questo errore:
SyntaxError: JSON.parse: expected ',' or ']' after array element at line 1 column 1198 of the JSON data
Come risolvo?
Grazie