Understanding the Difference Between Localhost:8080 and 127.0.0.1
I Am Trying to Create an Autocomplete Search Bar for a Website I Am Making, but I Keep Running into the Same Issue. It Functions as It Should When I Launch the...
I am trying to create an autocomplete search bar for a website I am making, but I keep running into the same issue. It functions as it should when I launch the Brackets live preview which prompts 127.0.0.1:..../.../.../ but when I press my home button which routes me to localhost:8080/.../.../, it doesn't seem to run the code. I think it has something to do with the jQuery call, telling the function in which circumstance to run, but I'm not entirely sure. I am using XAMPP.
function autocomplete(inp, arr) { ... }
Why does this occur?
Can you explain the difference between the two?
3 Answers
I think this can help you. A resume of that:
If you use 127.0.0.1, then (intelligent) software will just turn that directly into an IP address and use it. Some implementations of gethostbyname will detect the dotted format (and presumably the equivalent IPv6 format) and not do a lookup at all.
Copy of this answer*
You are not using port 8080 when you access the site with ip so I assume your site is listening on port 80. Can you try only without the port number
localhost will usually resolve to 127.0.0.1, but not always.
In normal configurations, localhost will point to either an address in the 127.x.x.x range (usually 127.0.0.1), or ::1 or similar if using IPv6. Some application implementations actually treat localhost specially, and when used can trigger a connection using something other than the IP stack (like shared memory, etc). Some IP stacks don't treat localhost as a special name, and you can manually have it resolve to any IP address you want. For example, by putting an entry into your hosts file.
But your problem is that when you used localhost, you specified port 8080, and when you used 127.0.0.1 you didn't specify a port, which would default to either 80 or 443 depending on if you used the http or https prefix.
127.0.0.1 is (usually) the equivalent of localhost 127.0.0.1:8080 is (usually) the equivalent of localhost:8080