The piece of code you sent is not the whole code, there should be xhr.open(...) .
It seems that the bug is in some place in your app code, not in the Bitnami's Lamp stack. To debug this you can use your browser dev tools. It can be that the code is running twice because it is linked to two differents events, this would explain that you see two open ports. Also, by the messages in the logs, it seems you have an php debugger running, that also would explain the two open ports in the browser.
In the the description of the issue, you said "... I think the server might be requesting a second copy....", the comunications always goes the other way around, from client (browser) to server. So, the problem has to be in the client side.
Please feel free to open an issue if you find and issue in the Lamp stack, but we can not help you too much with your app.
Rafael Rios Saavedra.