3

ajax 経由でフィードを解析しようとしましたGoogle Alertが、例外が発生しました。これは私が試したものです:

$(document).ready(function () {
    $.ajax({
        url: 'http://www.google.com/alerts/feeds/01662123773360489091/16526224428036307178',
        type: 'GET',
        dataType: "xml"
    }).done(function(xml) {
        $.each($("item", xml), function(i, e) {
            $("#results").append($("enclosure").attr("url").text() + "<br />");
        });
    });
});

しかし、私は得る:

XMLHttpRequest cannot load http://www.google.com/alerts/feeds/01662123773360489091/16526224428036307178. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. 

何か助けはありますか?


PS: ajax と jquery による RSS フィードの解析に関するいくつかの投稿を既に読みましたが、どれもうまくいきませんでした。

4

3 に答える 3

3

申し訳ありませんが、クロスドメイン スクリプトの使用は許可されません。ここで答えを見てください:

jQuery XML REST Access-Control-Allow-Origin

REST API のサーバー (あなたのサーバーではない) が、CORS (Cross-Origin Resource Sharing) HTTP ヘッダーを設定することによって、別のオリジンからのリクエストを許可している限り、たとえば "Access-Control-Allow -Origin" 応答の HTTP ヘッダー:

Access-Control-Allow-Origin: *

Google のヘッダーを見ると、そのオプションは提供されていません。

$ curl -I 'http://www.google.com/alerts/feeds/01662123773360489091/16526224428036307178'
HTTP/1.1 200 OK
Date: Sun, 26 Jan 2014 23:46:50 GMT
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Cache-Control: no-cache, must-revalidate
Content-Type: text/xml; charset=UTF-8
X-Frame-Options: DENY
Set-Cookie: PREF=ID=3c2ff90717c79524:TM=1390780010:LM=1390780010:S=f9cyzI-rk2Nca7W3; expires=Tue, 26-Jan-2016 23:46:50 GMT; path=/; domain=.google.com
X-Content-Type-Options: nosniff
Server: psfe
X-XSS-Protection: 1; mode=block
Alternate-Protocol: 80:quic
Transfer-Encoding: chunked

唯一の代替手段は、サーバーを使用して値を取得し、その値を jQuery アプリに中継することです。

于 2014-01-26T23:49:29.477 に答える