Javascript - Origin http://127.0.0.1 not allowed Access-Control-Allow-Origin

I am making a simple gallery that takes photos from picasa account with html + javascript.

First, gets a list of albums, and then, for each album, gets a list of photos. The first request works fine, but others return this error in the browser (Chrome):

GET https://picasaweb.google.com/data/entry/base/user/114476218463019618611/albumid/5750459375839674337?alt=json&hl=en_US 404 (not found) jquery.js: 8240 XMLHttpRequest cannot load https: // picas. google.com/data/entry/base/user/114476218463019618611/albumid/5750459375839674337?alt=json&hl=en_US . Source file: // not allowed Access-Control-Allow-Origin.

This is the code:

var json_Album_URI = "https://picasaweb.google.com/data/feed/base/" + "user/" + username + "?alt=" + "json" + "&kind=" + "album" + "&hl=" + "en_US" + "&fields=" + "entry(media:group,id)" + "&thumbsize=" + 104 + "&authkey=" + authkey; $.ajax({ type: 'GET', url: json_Album_URI, success : function(resp) { albums = resp.feed.entry; }, dataType: 'json', async: false }); for (var id in albums) { var album = albums[id]; var album_ID = album.id.$t.split('/')[9].split('?')[0]; var json_Photo_URI = "https://picasaweb.google.com/data/feed/base/" + "user/" + username + "/albumid/" + album_ID + "?alt=" + "json" + "&kind=" + "photo" + "&hl=" + "en_US" + "&fields=" + "entry(media:group)" + "&thumbsize=" + 104 + "&authkey=" + authkey; //this is the ajax call that fails $.ajax( { type: 'GET', url: json_Photo_URI, success: function(photos) { console.log(photos); }, dataType: "json", async: false, }); } 

Thanks.

EDIT:

I know that if I delete the line:

  + "/albumid/" + album_ID 

works (of course, with no expected response).

+6
source share
1 answer

It looks like CORS . Picasa header responses differ between the two requests. This succeeds when they include access-control-allow-origin:* .

Picasa includes it in: https://picasaweb.google.com/data/entry/base/user/114476218463019618611?alt=json&hl=en_US

But not at: https://picasaweb.google.com/data/entry/base/user/114476218463019618611/albumid/5750459375839674337?alt=json&hl=en_US

+1
source

Source: https://habr.com/ru/post/917444/


All Articles