For security reasons, a request like this won't work. Imagine if any domain could access any other domain's data - you'd end up with any site (e.g. www.sketchyattacksite.com) being able to pull arbitrary content from any other site (e.g. www.bankofamerica.com), including an authenticated user's confidential session information. The same origin policy, implemented by all modern browsers, exists to prevent such security violations from occurring.
There are a few common ways to get around the same origin policy:
- The domain you're requesting data from can return said data as JSONP (which lets you load it as if it were an external script, not subject to the same origin policy). Often sites will provide a JSONP format in their APIs, for example: https://graph.facebook.com/cocacola?callback=name_of_function_to_pass_data_via_jsonp
- Cross-Origin Resource Sharing (CORS) is a recent standard so will only work in newer browsers, but allows sites to specify (via an HTTP header) which domains they will allow to access their data. For example, if Bank of America for some reason wanted to allow www.sketchyattacksite.com to make requests to www.bankofamerica.com, they could return an
Access-Control-Allow-Origin: sketchyattacksite.com
header.
- A serverside proxy. You can create a handler on your server, the sole function of which is to retrieve your target
http://www.w3schools.com/ajax/cd_catalog.xml
file and return it on your domain. Note that this solves the problem of confidential data potentially being passed, because instead of the users' browser making the request, your server (which does not have access to the user's cookies on w3schools.com) does.
In this particular case it looks like #3, a serverside proxy, is the answer. Why? Because you don't have control of the site you're requesting the data from (meaning you can't take advantage of #1 or #2 unless the w3schools.com has itself chosen to implement them).
Here's a simple PHP example of a serverside proxy, courtesy of Yahoo!. The key is that it is locked down to only pull in content from specific domains (so that bad actors can't use it for arbitrary requests that appear to be made on your behalf), beyond that it's as simple as requesting the target URL via curl and returning it to the user. Note that you might also want to add caching to prevent every load of your serverside proxy from triggering a new request for the http://www.w3schools.com/ajax/cd_catalog.xml
file.