I am trying make a backend-frontend-mobile application with C#. Let there be a button, let it go to the 2nd page and show the graph of the work you did before.
When I run the codes, it sends it to ‘https://localhost:7191/’ instead of sending it to ‘https://localhost:8080/Graphic’.
Grafikcontroller.cs;
using Microsoft.AspNetCore.Mvc;
namespace YourProjectName.Controllers
{
[ApiController]
[Route("[controller]")]
public class GrafikController : ControllerBase
{
[HttpGet]
public IActionResult GetGrafikVerisi()
{
var grafikVerisi = new { x = new[] { 1, 2, 3, 4, 5 }, y = new[] { 5, 10, 15, 20, 25 } };
return Ok(grafikVerisi);
}
}
}
EmptyHtmlFile.html;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Grafik Gösterimi</title>
</head>
<body>
<div id="grafik"></div>
<button id="grafikGetir">Grafiği Getir</button>
<script>document.getElementById('grafikGetir').addEventListener('click', function () {
fetch('/Grafik')
.then(response => response.json())
.then(data => {
drawChart(data.x, data.y);
})
.catch(error => console.error('Grafik getirme hatası:', error));
});
function drawChart(xData, yData) {
}</script>
</body>
</html>
‘https://localhost:8080/Graphic’ after running the codes. While I was waiting to go to ‘https://localhost:7191/’ I was redirected to ‘https://localhost:7191/’.
İsmail Kıranlı is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.