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:
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.