I have the following code to save this data, but writing in the input
#primer-titulo
some tag, for example: <h1>esto es un ejemplo </h1>
goes to the error of ajax
, if I remove the tags <h1>
saves me all right.
If instead of the formdata
and step directly in the data, it works well but when passing images in base64
that weigh more than 1 mega the error is also gone. if I pass images less than 1 mega saves well.
Could you help me solve any of the 2 problems?
var Principal = {
Ptv: Cliente,
idioma: Lenguaje,
PrimerTitulo: $('#primer-titulo').val(),
SegundoTitulo: $('#segundo-titulo').val(),
TextoObligatorios: $('#texto-obligatorios').val().toString(),
TextoBoton: $('#texto-boton').val(),
ZonaCodigo: $('#zona-codigo-fotografia').val(),
Chec1: $('#chec-texto-1').val(),
Chec2: $('#chec-texto-2').val(),
Chec3: $('#chec-texto-3').val(),
ColorBoton: $('#color-boton').val(),
ColorEnglobante: $('#color-englobante').val(),
email: $('#email').val(),
titulo: $('#titulo').val(),
logo64: $('#img-logo64').val(),
ejemplo64_1: $('#img-ejemplo-1-64').val(),
ejemplo64_2: $('#img-ejemplo-2-64').val(),
fondo64: $('#img-fondo-64').val(),
ObligatorioCodigoFoto: $('#cod-foto-obligatorio').val(),
ObligatorioTextoNombre: $('#texto-nombre-obligatorio').val(),
ObligatorioTextoApellido1: $('#texto-apellido1-obligatorio').val(),
InvalidoTextoEmail: $('#texto-email-invalido').val(),
ObligatorioTextoPais: $('#texto-pais-obligatorio').val(),
InvalidoTextoFount: $('#texto-codigo-fount').val()
}
var formdata = new FormData();
for (var key in Principal) {
formdata.append(key, Principal[key]);
}
console.log(formdata)
$.ajax({
type: 'POST',
url: '../../Home/EditarPrincipal/',
processData: false,
contentType: false,
data: formdata,
success: function (data) {
if (data.b) {
$('#editar-principal').prop("disabled", true);
swal("Información", data.msj, "success").then((value) => {
location.reload();
});
} else {
swal("Información", data.msj, "warning");
}
},
error: function (jqXHR, textStatus, error) {
swal("Información", "Error al hacer peticion al servidor", "error");
}
});
});
Driver
[HttpPost]
public JsonResult EditarPrincipal(Principal DatosPrincipal)
{
bool result = false;
try
{
List<ConfiguracionGeneral> processData = ConvertToConfigurationInitial(DatosPrincipal);
result = _ConfiguracionService.UpdateConfiguration(processData, int.Parse(DatosPrincipal.idioma), int.Parse(DatosPrincipal.Ptv),"InicialDescarga");
if (result)
return Json(new { b = result, msj = "Editado pagina principal con exito" }, JsonRequestBehavior.AllowGet);
else
return Json(new { b = result, msj = "Ocurrio un error al guardar los datos de la pagina principal" }, JsonRequestBehavior.AllowGet);
}
catch
{
return Json(new { b = result, msj = "Error al editar pagina principal" }, JsonRequestBehavior.AllowGet);
}
}
WebConfig
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" maxRequestLength="50000000" executionTimeout="1200" requestValidationMode="2.0" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>