0

I am building a web application where I need to get XML data from several cross-domain feeds.

The annoying thing is: they're cross-domain. I currently use a jQuery (script) on the "local" domain, which fetches the XML from the other domain.

For enabling CORS I added headers and here is my code

$.ajax({
            url: '/CurrencyConvertor.asmx/ConversionRateFromCurrency=USD&ToCurrency=INR',
            type: 'post',
            crossDomain: true,
            ContentType: 'application/xml',
            Origin: 'http://www.webservicex.net',
            headers: {
                'Access-Control-Allow origin': 'http://www.webservicex.net',
                'Access-Control-Allow-Credentials': 'true',
                'Request Headers CAUTION': 'Provisional headers are shown',
                'Access-Control-Request-Headers': 'accept, content-type',
                'Access-Control-Allow-Methods': 'GET,POST'

            })

but still I'm getting CORS problem while I was running in Firefox

and the error I'm getting is

Accept  
*/*
Accept-Encoding 
gzip, deflate
Accept-Language 
en-US,en;q=0.5
Access-Control-Allow-Cred...    
true
Access-Control-Allow-Orig...    
http://www.webservicex.net
Cookie  
_ga=GA1.1.256593039.1431427019
Host    
localhost:8383
Referer 
http://localhost:8383/CordovaApp/index3.html
User-Agent  
Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Ivan Sivak
  • 7,178
  • 3
  • 36
  • 42
  • 1
    `Access-Control-Allow-Origin` and friends are **response** headers, not request headers. Your JavaScript can't give itself permission to access content across origins. – Quentin Jun 04 '15 at 11:16
  • 1
    "and the error I'm getting is" —That isn't an error. It's a (badly formatted) by perfectly normal (aside from trying to set access control) request header. – Quentin Jun 04 '15 at 11:16
  • `ContentType: 'application/xml',` — You haven't set `data` to anything. Since you aren't POSTing any data, why are you saying that the data you are posting is an XML document? – Quentin Jun 04 '15 at 11:17
  • `Origin: 'http://www.webservicex.net',` — Why are you trying to set this explicitly? The browser adds the origin header automatically. – Quentin Jun 04 '15 at 11:18
  • `crossDomain: true,` — why are you setting this? You said your script is returning data from other origins, not that it redirects to them. – Quentin Jun 04 '15 at 11:18
  • I'm not getting any data, that is Why I'm setting crossDomain: true and it is not even hitting the service – Kheerthi imandi Jun 04 '15 at 13:17
  • What makes you think it isn't even hitting the service? Does the Net tab of your developer tools display a time out error? – Quentin Jun 04 '15 at 13:20
  • yes, and while I was running in chrome it was showing me Failed to load resource: net::ERR_EMPTY_RESPONSE http://localahost:8383/CordovaApp/cordava.js Failed to load resource: net::ERR_EMPTY_RESPONSE http://localahost:8383/CordovaApp/favicon.ico Failed to load resource: net::ERR_EMPTY_RESPONSE http://localahost:8383/CordovaApp/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=INR – Kheerthi imandi Jun 04 '15 at 13:51
  • And I 'm problem if it is calling http://localhost:8383/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=INR but I need to call http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=INR could you help me out with this problem – Kheerthi imandi Jun 04 '15 at 13:51
  • In both cases it sounds like you just need to type the URLs you actually want. If you want an absolute URL then start it with `http://` and then specify the domain instead of making it relative to your current site. If you want `localhost` then type `localhost` and not `localahost` with an extra `a`. – Quentin Jun 04 '15 at 13:57
  • In my scenario, I'm trying to us http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=INR for that I wrote ajax call as mention above but still it is going to my domain i,e, localhost:8383 http://localhost:8383/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=INR so could you guide me like how to call www.webservicex.net domain instead of my domain ,i.e, localhost:8383 – Kheerthi imandi Jun 04 '15 at 14:01
  • You change `url: '/CurrencyConve` to `url: 'http://webservicex.net//CurrencyConve` – Quentin Jun 04 '15 at 14:13
  • Still I'm getting error as Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=INR. (Reason: CORS header 'Access-Control-Allow-Origin' missing). Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=INR. (Reason: CORS request failed). – Kheerthi imandi Jun 04 '15 at 14:17
  • Then you need to get webservicex.net to give your JavaScript permission to access the data (or use a proxy) – Quentin Jun 04 '15 at 14:18
  • can explain how to access data in JavaScript using webservicex.net or how to set/use proxy – Kheerthi imandi Jun 04 '15 at 14:25
  • http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy – Quentin Jun 04 '15 at 14:29
  • can you explain briefly or else send some link as reference on how to to access data in JavaScript using webservicex.net – Kheerthi imandi Jun 04 '15 at 14:51
  • http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy – Quentin Jun 04 '15 at 15:09

0 Answers0