Good morning.
I have a Javascript process that makes a POST call to a controller, and I'm getting Internal Server 500 error, and in jquery this line marks me
xhr.send( options.hasContent && options.data || null );
This only happens if I return empty data from the controller. If you perform the correct process does not leave that error. The problem is that it is a continuous call to that controller and the console fills me with error messages, although the operation of the program is correct.
I leave you the javascript code and the controller.
function getMessagesUser(e) {
//Una vez cargada la página pinto el historial de mensajes de esa conversación.
var values = {
"userID": "11",
"appID": "22"
};
$.ajax({
url: urlControl + "/GetMessages",
dataType: "json",
type: "POST",
data: values,
success: function (msgsUser) {
if (msgsUser != null && msgsUser != "") {
for (x = 0; x < msgsUser.length; x++) {
//Realizo la acción
}
}
},
failure: function (errMsg) {
console.log(errMsg);
}
});
var timer = setTimeout(getMessagesUser, 5000);
}
The controller
[HttpPost("GetMessages")]
public async Task<IActionResult> GetMessages([FromServices] IChat AC)
{
//Busco mensajes pendientes para ese usuario
List<MessageUser> listMsg = await AC.GetMessagesPending();
var resultMsg = listMsg;//Hago copia de la lista que se va a enviar
if (resultMsg != null)
{
return Json(resultMsg);
}
return Json(String.Empty);
}
If there is data, it returns it correctly and it looks good on the screen, but if there are no messages to return, for each call made by the javascript, that message appears.
Can you help me please?