0

プロジェクトにクロスドメインデータアクセスが必要で、それを機能させましたが、This page is accessing information.ブラウザー設定を明示的に変更して抑制したくないというこのポップアップでスタックします。このメッセージを抑制するように作業コードを変更できますか?

ポップアップ付きの私の作業コード:

 <script type="text/javascript">$.ajax({
     url: "http://sys85/testservice/serviceCall.ashx",
    dataType: "text",
    type: 'get',
    crossDomain: true,
    success: function (data) {

    },
    error: function (jqXHR, textStatus, errorThrown) {
        if (window.console) console.log("Error... " + textStatus + "        " + errorThrown);

    }
});
</script>

私はここに与えられた例で試しました:jsonp with jquery、しかし私のURLではそれは機能しません。

結果を返すハンドラーファイル(serviceCall.ashx):

string result = "121";
context.Response.ContentType = "application/json";
context.Response.Write(result);

ハンドラーファイルを変更する必要がありますか?

エラーの詳細を取得するためにエラー関数を追加しようとすると、次のようになります。

$(document).ready(function () {

    var url = "http://sys85/testservice/serviceCall.ashx";
    $.getJSON(url + "?callback=?", null, function (data) {
        alert(data);
    })
    .error(function (jqXHR, textStatus, errorThrown) {
        console.log("Error... " + textStatus + "        " + errorThrown);
        document.getElementById('lblmsg').value = "Error... " + textStatus + "        " + errorThrown;
    })
});

このエラーが発生します:Uncaught TypeError: Object #<XMLHttpRequest> has no method 'error'

このメッセージを取り除くために可能なすべての方法を試しました。

4

1 に答える 1

0

$.ajax最初の例と同じように、代わりに jquerys メソッドでエラー コールバックを使用します。

getJSON私の知る限り、エラー コールバックはなく、dataType$.ajaxを「json」に設定した場合の省略形です。

于 2012-06-11T16:59:13.760 に答える