Sunday, July 05, 2009

Not the same origin

By the way, Firefox 3.5 allows you to make XMLHttpRequests cross domain (in other words code loaded from some domain foo.com can make XHR requests to domain bar.com). Mozilla's spec suggests a special HTTP header for that:

Access-Control-Allow-Origin: *

with this header your server informs client that cross domain request is Ok from any domain. Instead of * you can use there a name of domain allowed to perform cross domain requests.

And here is Java servlets filter from JSOS lets you add such a header to your site so cross domain requests could be allowed for existing web applications - Cross domain Ajax filter.

6 comments:

Sönke said...

Hi there,

I came across your cross domain ajax site and tried to get it running. I didn't succeed. Here is my minimal example:

-----------------------------------------------

When I call this page ...
http://squid-games.appspot.com/local.html

...it nicely reads this one.
http://squid-games.appspot.com/requested.html

But when I download local.html and run it on the Desktop or on my blog's domain the request returns an empty string and XmlHttpRequest.status = 0.

The crossdomainajaxflt.jar is located in WEB-INF/lib and my web app says:


.
.
.

CrossDomainAjaxFilter
com.cj.access.CrossDomainAjaxFilter




-----------------------------------------------

What am I doing wrong? Any idea?

Thanks
Sönke

Anonymous said...

And what was saying in your web app?
It looks like there is some error

Sönke said...

oh sorry, the commenting function just removed the < > braces. Another try - web.xml:

<web-app>
   .
   .
  <filter>
    <filter-name>CrossDomainAjaxFilter</filter-name>
    <filter-class>com.cj.access.CrossDomainAjaxFilter</filter-class>
  </filter>
</web-app>

I had some typos first but this lead to a GAE server error 500. What I post here is currently running (as you can call the URLs posted before). But it just refuses ajax calls from another domain/my local file system.

Thanks for your time
Sönke

Abava said...

>braces. Another try - web.xml:
it is a description for the filter. Did you add mapping also?

Sönke said...

Nope - just wanted to create a minimal example. Is a mapping required? Because I understood: "By default filter allows cross domain requests from any domain". Maybe a complete example of the web.xml would make it more comprehensible then.

Do you have a running instance that I could AJAX-request from my server? Just to make sure the problem is not in my scripts.

Abava said...

>Is a mapping required?
Yes. Mapping describes what request will be serviced by the filter. Without mapping filter simply does not work