this is what I am trying to do.
I have made a few .html pages with JavaScript code in it and hosted them on a Yahoo server.
Now when a client with a certain browser views these web pages, the JavaScript code uses XMLHTTPRequest
to make a connection at h1ttp://localhost:8080/myservlet/servlet1 to read some data.
I know, I want to connect to the web server running on the client's computer if the client has one i.e. I am using localhost in my xmlHTTPRequest.
But this is not working even when a client has a web server running on port 8080. On the client's computer I can access http://localhost:8080/mysevlet/servlet1
and the servlet is running fine, but through the .html
page hosted on Yahoo server it does not work.
Anything that I am doing wrong here?
You are accesing localhost , meaning you have a web server running on your machine. To access it from Internet, you need to assign a public IP address to your machine. Then you can access http://<public_ip>:<port>/ .
localhost is a special hostname that almost always resolves to 127.0. 0.1. If you ask someone else to connect to http://localhost they'll be connecting to their computer instead or yours. To share your web server with someone else you'll need to find your IP address or your hostname and provide that to them instead.
JavaScript. Web browsers (aka clients) can also run JavaScript code. This is client-side code that runs on your computer. (It's also possible to run JavaScript on a server, but that's a bit outside the scope of this tutorial.)
Cross-site Scripting
You cannot access what is not on your domain, unless it is a Web Service returning XML or JSONP
Due to policy restrictions browsers do not allow you to send XMLHttpRequest to domains different than the domain hosting the web page which in your case is Yahoo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With