Want XML from an other website via JavaScript (AJAX)?
This dictates that content should be restricted to a single origin (scheme+host+port), for session security, and although it has not been strictly adhered to in browsers of the past, modern browsers are beginning to implement this policy more closely.
The problem is that, as always with these things progress is slow, and some browsers notably IE9, have implemented the security by simply locking down and not allowing for access by any means ("No Transport" error).
edit: turns out, IE8 & and IE9 do allow for limited support with the XDomainRequest object, for IE6 & 7 you could use flash as a work around.
Other browsers have allowed such access using CORS which allows the server to decide what origins to allow access to its resource.
(Of course if you were talking JSON and not XML there is a convenient Hack called JSONP which will get you around the SOP in all browsers)
CORS is implemented in the browser, your client-side code and the services you access, so requires work for service providers as well to get it working.
For a Simple Cross-Origin Request, you should pass the Origin header in the service call, using jQuery, this is done by setting crossDomain to true (jQuery will check the domain you're on and the one you're calling to do this automagically).
$.ajax(
"http://cor.sandbox/services/dataservice.svc/getdata",
{
type: "GET",
crossDomain: true
});This will pass the following sort of thing to the server
GET http://cor.sandbox/services/dataservice.svc/getdata HTTP/1.1 Host: cor.sandbox Connection: keep-alive Origin: http://localhost:58264 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) Accept: */*edit: in the case of IE9, the original call will not be made at all as jQuery core does not currently iron out the XDomainRequest wrinkle, there is discussion about this being added, its not clear whether they will or not
The server should then return headers in the response which allow the browser to accept the returned data, if they are not returned, the browser will reject
HTTP/1.1 200 OK Content-Length: 184 Content-Type: application/xml; charset=utf-8 Access-Control-Allow-Origin: *
In ASP.NET you can add the following to web.config to return these headers, although its a sledge-hammer solution
<system.webServer> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol> </system.webServer>
http://www.w3.org/Security/wiki/Same_Origin_Policy
http://en.wikipedia.org/wiki/Same_origin_policy
http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing
http://en.wikipedia.org/wiki/JSONP
http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/
http://encosia.com/using-cors-to-access-asp-net-services-across-domains/
| < | May 2012 | |||||
|---|---|---|---|---|---|---|
| S | M | T | W | T | F | S |
| 29 | 30 | 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 | 31 | 1 | 2 |
Add-ins AJAX ASP.NET MVC Browsers C# Caching CodeDom Compression CORS CSS CV Data Database DependencyResolver Development Dynamic Entity Framework Error Handling Extend File Upload Forms GDI+ HTML HTML Editor HTTP Interfaces JavaScript JQuery MCE MetadataProvider MSBuild Numbers Objects Patterns Progressive Enhancement Projects Publish Regex Resources Security SEO SMTP Source Control Strings Sub-Collections TDD Templates Tools Twitter User Interface WCF Web Development WHS WMC XLinq XML
15/05/2012
WindowsAzure
Announcing the MEET Windows Azure Event! Streamed online June 7th. Register at http://t.co/bObzTAuL #MEETAzure #WindowsAzure
10/05/2012
kevinwhinnery
Comparing Titanium and PhoneGap - A common question I get asked at developer events and conferences is how... http://t.co/Zq2eND6B
09/05/2012
brianleroux
PhoneGap goals and philosophy: http://t.co/wkq8wI2T
just now
ChaseDiane
encrypting phonegap android by joseesfera: currently being developed for PhoneGap app, we need to encrypt the co... http://t.co/qCSGs9iX
just now
rgonv
#Tech Post: Bing Search API now available on Windows Azure Marketplace: The Bing Search API is now available on ... http://t.co/iBvXOjbC