Receiving an Error When Trying to Test with Localhost

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 = "";
$().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  net::ERR_CONNECTION_REFUSED`
16

1 Answer

@Bravo Thank you for your help I was able to find out why it wasn't functioning correctly. So changing the port on LiveServer to match the port in my code ended up solving the initial problem that I had. As for the function error I received I was able to solve that easily. I did not realize that I had Books.foreach written instead of Books.forEach. It also looks like I forgot to use the # for some of my processing functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest