问题
I'v been struggling with POST on the Picasa API. Here's code:
$.ajax({
type: "POST",
url: 'https://picasaweb.google.com/data/feed/api/user/' + uid + '/albumid/' + album_id + '/photoid/' + photo_id,
crossDomain: true,
data: { content: content },
success: function() { alert("Success"); },
error: function() { alert('Failed!'); }
});
I've already retrieved some information via GET without problems.
Now comes the fun part, when I try to test the service with Google this error occurs:
XMLHttpRequest cannot load
https://picasaweb.google.com/data/feed/api/user/userid/albumid/albumid/photoid/photoid?content=foo%bar.
Origin http://localhost:3000 is not allowed by
Access-Control-Allow-Origin
.
And when I try in Firefox the request header method is changed to OPTIONS
and status is 204: no content
.
Also, I've tried to change datatype
to jsonp
but then HTTP method changes to GET
and it retrieves information about the picture.
回答1:
Access-Control-Allow-Origin
is coming because your are making a ajax call to a server which is not same as your current domain.
Read more here
jsonp
will not help for POST
request because you can only make GET
request with jsonp
.
IMHO you should try to make the POST request from server side instead of client side script.
来源:https://stackoverflow.com/questions/13514355/post-request-to-picasa-api