nxt's place

Search


Calendar

« November 2008
MonTueWedThuFriSatSun
     
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
       
Today


Tag Cloud

3com acer ajax apr awt buitenkunst c++ car charva cross debug design domain drop dwr ejb fold fuse glass google gui ie injection ipv6 jboss jna jni linux looking microsoft mime native newsgroup nntp remoting resource router rss scm software ssl subversion sun superversion svn swing travel ui web zangwerkplaats

cross domain AJAX

November 25, 2006 by nxt

Using AJAX (which implies the use of the XMLHttpRequest) has one big limitation, you can only make requests to the server from where the page was downloaded.
As an alternative you can use javascript to dynamically include other javascript files which should be generated serverside.

An example on how to call the server:

function callServer() {
 var head = document.getElementsByTagName("head").item(0);
 var myTag = document.createElement("script");
 myTag.setAttribute("type", "text/javascript");
 myTag.setAttribute("src",
  "http://example.com/application/getjs/?var1=value1");
 head.appendChild(myTag);
}

The idea is that you generate the javascript that you need by dynamically add another script tag on the page.
for an excellent example of this approach you can read this javaworld article