Automatically find IP address Raspberry Pi on same subnet using Javascript

I have a Raspberry Pi that is connected to my network and a Samsung Gear S that is connected to the same network. The Raspberry Pi is used as a server and the Gear S sends data to it. I currently need to insert the Raspberry Pi IP address manually in the Gear S app whenever I connect to another network. I’ve found that you can use raspberrypi.local and that the raspberry pi will recognize this address as it owns. My problem is that when I try to post something to the address “http://raspberrypi.local:8080/appdata/post” using Javascript, the post doesn’t come true. I suppose that raspberrypi.local cannot be resolved. How can I solve this?