简体   繁体   中英

Expedia API Cross Origin Requests

I'm playing around with a hotel search frontend using the Expedia API . I set up a node.js server running on localhost:3000 and a simple Backbone view for entering location and dates.

However when submitting the request to Expedia, I always get

XMLHttpRequest cannot load ... http://localhost:3000 is not allowed by Access-Control-Allow-Origin.

Here is my submit code, which should work fine:

$.support.cors = true; // not really done at every request
var from = this.$el.find( "input[name=date-from_submit]" ).val(),
    to = this.$el.find( "input[name=date-to_submit]" ).val(),
    where = this.ui.place.val();

$.ajax({ 
    "url": "http://api.ean.com/ean-services/rs/hotel/v3/list?" + 
      "destinationString=" + where +
      "&cid=55505" + //test CID
      "&minorRev=20" +  
      "&arrivalDate=" + from + 
      "&departureDate=" + to +
      "&room1=2" + 
      "&apiKey=<apikey>",
    "dataType": "json",
    "accept": "application/json"
}).always( function( a, b, c ) {
    console.debug( a, b, c );
});

I tried this code from a JSFiddle to see if they only prohibit localhost , but no avail. Same Origin Policy error again.

Now I'm wondering:

  1. Does Expedia support Cross Origin Requests at all?
  2. Maybe I'm supposed to enter the Origin of my choice somewhere on their website? I didn't find anything.
  3. If the answer to 1. is "No", then how are developers supposed to build a product with their API?
  4. Am I just stupid?

Thanks in advance!

Use dataType:"jsonp"

$.ajax({
cors:true,
dataType:"jsonp",   
url:"API END POINT",
method:"GET",
success:function(data){
    console.log(data);
}

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM