The typical way for sending a request to a different domain is to use a proxy.
For example, if you were on the domain example.org, and you wanted to make a request to an Ajaxy service on example2.org, you'd set up a server-side proxy on example.org and that script passes the request on to example2.org, and when it receives the response from example2.org, sends that back to the browser.
Here's more details, along with some code examples of a proxy:
http://developer.yahoo.com/javascript/howto-proxy.htmlThere is a second method, which is good enough if you can get by with just GET requests, that's using the script element. So in javascript you create a new script node in DOM, and then add that to the document. The src attribute would be the full URL including query string parameters if any. By inserting the script element into the document fires off a request to the actual server. As long as that server writes the JavaScript response in a manner that can be reused by the page - like calling a predetermined function with the response data sent as arguments.
So to fire off a new request:
var newRequest = document.createElement('script');
var requestUrl = '
http://www.externalDomain.com/ajaxHandler.php?name=myName&password=myPassword';newRequest.src = requestUrl;
document.getElementsByTag('head')[0].appendChild(newRequest);
Then the server side script at
http://www.externalDomain.com/ajaxHandler.php returns pure JavaScript:
myPredeterminedFunction({
status: 'OK',
message: 'username and password authorised.'
});
that calls a function called myPrederminedFunction, passing in the object literal as a value, so on our existing page, we'd already have a function:
function myPredeterminedFunction(response) {
alert(response.message);
}