Hello everyone, I recently upgraded my ASP.Net Core 2 MVC app to .Net 6, and ever since then, I've been experiencing a strange issue. The XMLHttpRequest responses I receive are always empty, showing "{}" or [{},{},{},{}] for arrays, even though the backend is actually sending data.
For example, consider the controller method TestLoad that returns a simple class TestClass. When I debug and break on the return line, the value returned seems fine (refer to this image for debug info): backend
public class TestClass
{
public int id = 0;
public string title = "Title";
public bool active = false;
}
public JsonResult TestLoad()
{
TestClass testClass = new TestClass();
testClass.id = 10;
testClass.title = "Yeah man!";
testClass.active = true;
JsonResult jsonRes = Json(testClass);
return jsonRes;
}
However, when I check the frontend, I see an empty object being received, not undefined or null, but truly an empty object (check this image for debug info): frontend
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var dt = JSON.parse(xmlhttp.responseText);
if (dt == 'err') {
alert('error');
}
else if (dt !== null) {
alert(dt.title);
}
}
else {
alert(xmlhttp.status);
}
}
}
ldwait(false, false);
xmlhttp.open("GET", rv + "ajxGame/TestLoad", true);
xmlhttp.setRequestHeader('Cache-Control', 'no-store');
xmlhttp.setRequestHeader("Content-Type", "application/json");
xmlhttp.send();
I would greatly appreciate any help or insights into why this could be happening. My code remains unchanged, only the migration from .Net Core 2 to .Net 6 has taken place.
Thank you in advance!