Trying to perform a "get" request to API. I know the API will return the data when I do the "get" from Postman. So I believe the problem is with my HTML.
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<script>
const Http = new XMLHttpRequest();
const url='https://localhost:44369';
Http.open("GET", url);
Http.send();
Http.onreadystatechange = (e) => {
console.log(Http.responseText)
}
</script>
</body>
</html>
Here's the API method I'm trying to "get" from:
//https://localhost:44369/api/Request
[EnableCors("AllowLocalhostOrigins")]
[HttpGet]
public ActionResult GetText()
{
string a = "b";
return Ok(a);
}
Here's the error I'm getting: 404 Not Found
After doing some more reading, I see that it's a problem with the API and not the html code I posted this question about. The html code I posted works fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.