I am having an issue with my code but I can't seem to figure it out. When I run LiveServer with Visual Studio the website loads but as soon as I click the "GET" button that I put in it throws "ERR_CONNECTION_REFUSED". I decided to dig a little deeper with inspect source and it pointed to this line of code:
xhr.send();
This is exactly how my professor is showing us how to do it and it works good for him so I don't really understand my issue. I've already tried disabling my ad blocker, dns flush, deselecting "use proxy for LAN". The browsers I've tested so far have been Chrome, Brave, and Edge to no success. Here is my code as well as my exact error for anyone who may be curious:
let url = "http://localhost:8080/api/";
$().ready(()=>{
//GET Button
$('#btn-get').click(()=>{
$("#ajax-form").html ( getDeleteForm('get') )
$("#go-get-delete").click(()=>{
//get id from form
let id = $("#form-get-delete #id").val();
//create AJAX call
var xhr = new XMLHttpRequest();
xhr.open('GET',url + id);
xhr.send();
xhr.onreadystatechange = ()=>{
if(xhr.readyState == 4 && xhr.status == 200){
//Convert data to JS object
let books = JSON.parse(xhr.responseText);
processResult(books,'GET');
}
}```
`GET http://localhost:8080/api/ net::ERR_CONNECTION_REFUSED`