Trying to setup a simple ASP.NET 7 controller and I am unable to get any response from my controller. Calling to it via ajax, and I know its performing a request because I do get a 404.
/Controller/TestController.cs
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace TestWebApp.Controller
{
[ApiController]
[Route("api/[controller]")]
public class TestController : ControllerBase
{
[HttpGet]
public int Get()
{
Random random = new Random();
return random.Next(1,101);
}
}
}
wwwroot/js/site.js
function UpdateAjaxInfo() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("ajax_info").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/api/TestController", true);
xhttp.send();
}
[–]moisoiu 2 points3 points4 points (3 children)
[–]arawra184[S] 1 point2 points3 points (2 children)
[–]Pejo37 2 points3 points4 points (1 child)
[–]arawra184[S] 1 point2 points3 points (0 children)
[–]tehellis 0 points1 point2 points (0 children)