0

jQuery を介して別のドメイン (信頼できるドメイン) からファイル/データをフェッチすることが可能かどうかを判断し、アイテムが正常にフェッチされたかどうかを判断しようとしています。つまり、このメソッドを使用して、ユーザーがブラウザでこのサイトを信頼できるサイトとして設定しているかどうかをテストしたいと考えています。経由でテストを行いましimg.src=[image on the 'another domain']たが、常に成功しました。つまり、信頼が確立されているかどうかに関係なく、認証を要求しませんでした。そのため、別の解決策/推奨事項を探しています..

ありがとう

4

2 に答える 2

1

次のプラグインを使用できます-http://binarykitten.me.uk/dev/jq-plugins/88-jquery-plugin-ajax-head-request.html

この関数は、渡されたURLを呼び出し、データを渡して、完了時にヘッダーを処理します。

ユーザーがサイトにアクセスできる場合、つまり認証されている場合は、ステータスコード200が表示されます。そうでない場合は、ステータスコード401を受け取ります

HTTPステータスコード:http ://w3.org/Protocols/rfc2616/rfc2616-sec10.html

于 2011-11-16T14:52:59.350 に答える
0
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Show Content</title>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript"> 
            $(document).ready(function() {
                // this script resides on aaaa.yyyyy.domain.com
                document.domain='yyyy.domain.com';
                // call to trusted site
                var urlx="http://bbbb.yyyy.domain.com";

                // turn on x dom calls
                jQuery.support.cors = true; 

                // Launch AJAX request.
                $.ajax(
                    {
                        url: urlx,

                        // The type of request.
                        type: "head",

                        // The type of data that is getting returned.
                        dataType: "html",

                         error:function 
                         (xhr, ajaxOptions, thrownError){  
                            ShowStatus( "Call to URL: '"+urlx+ "' Failed "+xhr.status+" "+thrownError);
                         },
                        success: function( strData ){
                            ShowStatus( "Call to URL: '"+urlx+ "' Success");
                        }
                    }
                );
            });

            function ShowStatus( strStatus ){
                var jStatusList = $( "#ajax-status" );
                jStatusList.prepend( "<p>" + strStatus + "</p>" );
            }
        </script> 
    </head>
    <body>
        <div id="ajax-status" ></div>
    </body>
</html>
于 2011-11-29T12:24:14.930 に答える