Controller code:
[Route("api/[controller]")]
[ApiController]
public class AjaxController : ControllerBase
{
ApplicationDbContext dbContext = null;
public AjaxController(ApplicationDbContext ctx)
{
dbContext = ctx;
}
[HttpGet]
[Route("GetString")]
public string GetString()
{
return "Hello World";
}
[HttpGet]
[Route("GetCategories")]
public Category[] GetCategories()
{
return dbContext.Categories.ToArray();
}
}
Angular code:
http.get<string>(baseUrl + 'api/ajax/GetString').subscribe(result => {
console.log(result);
}, error => console.error(error));
While Angular can parse without error the GetCategories endpoint, it cannot parse the much simpler GetString. Why? The error in the console is:
error: SyntaxError: "JSON.parse: unexpected character at line 1 column 1 of the JSON data" text: "Hello World"
I tried wit Postman and the response is just fine, see screenshot:

console.logit? The error to me indicates that there is invalid JSON