Connecting to Remote Servers and JavaScript Security
You may be surprised to find out that the PHP exercises you have just completed worked smoothly because the server (PHP) scripts you called asynchronously were running on the same server from which the HTML file was loaded.
Web browsers have very strict (and different) ways to control what resources you can access from the JavaScript code. If you want to access another server from your JavaScript code, it is safe to say that you are in trouble. And this is what we will do in the exercise that follows; but before that, let’s learn a bit of theory first.
So, the JavaScript code runs under the security privileges of its parent HTML file. By default, when you load an HTML page from a server, the JavaScript code in that HTML page will be allowed to make HTTP requests only to that server. Any other server is a potential enemy, and (unfortunately) these enemies are handled differently by each browser.
Internet Explorer is a friendly kind of web...