Pazartesi, Ekim 08, 2007
Crossdomain AJAX calls
If you've tampered around long enough with Javascript, you've definitely come across the problem with loading data from another domain. JS wont let you make XML Http Requests to a domain different then where the original Javascript code was loaded from. This is a security precaution to prevent cross site scripting etc. There are a few methods around this, like using a serverside proxy that makes the external calls for you, but this is the most primative solution you could come up with. Does it work? Sure it does but the purpose of this post is not to get you the working solution, but to tease your mind. Interesting article that I came across, when reading a chinese dudes article on client side load balancing (with was implemented decades ago using the client side clock and modulus arithmatic to redirect calls to different sub domains), lead me to another interesting method for making cross domain calls via javascript: The dynamic script tag method. The only pre-requist of this method is that the webservice you are calling must respond in JSON. The only trick is to add a tag element dynamically to the DOM tree, that has the SRC attribute set to the URL of the web service that sends the data in JSON. The cool thing here is that the JSON response is evaluated automatically, so you get your JS object.
Kaydol:
Kayıt Yorumları (Atom)

0 yorum:
Yorum Gönder