ここで本当に奇妙なことが起こっています。フェッチしようとしているモデルがあります。Fiddler で呼び出しを確認したり、API サービスを手動で呼び出したりすると、期待どおりの JSON が返されますが、バックボーンでフェッチ メソッドが常にエラーをスローします。理由はわかりませんが、responseText は空です。fiddler では、サービスは 200 を返します。
これが呼び出しコードです...
    this.createSession = function (sessionId) {
            var that = this;
            CookieManager.CreateSession(sessionId);
            var sessionData = new Authentication.Response({
                id: sessionId 
            });
            sessionData.fetch({
                success: function () {
                    that.storeData(sessionData);
                },
                error: function (model, xhr) {
                    if (console !== undefined && console !== null) {
                        console.log('Unable to load session data: ' + xhr.responseText);
                    }
                    throw new Error('Unable to load session data');
                }
            });
        };
そして気になるモデルは…
define(['ministry', 'moment'],
function (Ministry) {
    var authRequest = Ministry.Model.extend({
        name: 'Auth Request',
        urlRoot: '/api/auth',
        defaults: {
            id: undefined,
            requestSource: undefined,
            apiKey: undefined,
            username: undefined,
            password: undefined,
            dateCreated: undefined,
            lastLoggedIn: undefined
        },
        generatedHash: undefined,
        parse: function(attributes, response) {
            var hashUrl = response.xhr.getResponseHeader('location');
            var elements = hashUrl.split("/");
            this.generatedHash = attributes.id = elements[elements.length - 1].toLowerCase();
            return attributes;
        },
        validate: function (attributes) {
            if (attributes.requestSource === undefined || attributes.requestSource == null || attributes.requestSource == '') {
                return "The attribute 'requestSource' is required";
            }
            if (attributes.apiKey === undefined || attributes.apiKey == null || attributes.apiKey == '') {
                return "The attribute 'apiKey' is required";
            }
            if (attributes.username === undefined || attributes.username == null || attributes.username == '') {
                return "The attribute 'username' is required";
            }
            if (attributes.password === undefined || attributes.password == null || attributes.password == '') {
                return "The attribute 'password' is required";
            }
            return null;
        }
    });
    // Return as two types for syntactic sugar reasons.
    return {
        Request: authRequest,
        Response: authRequest
    };
});
このモデルは、共通のルート モデルを拡張したもので、そのコードはここにあります...
  var ministryModel = Backbone.Model.extend({
        name: 'Unnamed Model',
        initialize: function (options) {
            this.options = options || {};
            Backbone.Model.prototype.initialize.call(this, options);
            if (this.options.name) {
                this.name = this.options.name;
            }
            this.on('invalid', function (model, error) {
                if (console !== undefined) {
                    console.log(error);
                    console.log(model);
                }
                throw (new Error(error));
            });
        },
        fetch: function (options) {
            this.trigger('fetching', this, options);
            return Backbone.Model.prototype.fetch.call(this, options);
        }
    });
エラー コールバックが常に呼び出されており、その理由がわかりません。Fiddler では、API を直接呼び出すと次のようになります...
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 19 Aug 2013 16:12:00 GMT
Content-Length: 213
{"id":"bba5e742d1af3de5921e8df0a1818530789c202a","dateCreated":"2013-07-22T17:57:20.143","lastLoggedIn":"2013-08-19T17:08:29.67","username":"tiefling","apiKey":"ka73nd9s7n2ls9f3ka2n5p2k","requestSource":"website"}
そして、これはChromeからの呼び出しに問い合わせるとき...
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 19 Aug 2013 16:08:29 GMT
Content-Length: 213
{"id":"bba5e742d1af3de5921e8df0a1818530789c202a","dateCreated":"2013-07-22T17:57:20.143","lastLoggedIn":"2013-08-19T17:08:29.67","username":"tiefling","apiKey":"ka73nd9s7n2ls9f3ka2n5p2k","requestSource":"website"}
どちらも 200 を示していますが、Fiddler では少し異なるアイコンを示しています。Chrome の呼び出しアイコンは赤い円ですが、それ以外はすべてハンキー ドリーに見えます。
どんなアイデアでも歓迎します。今のところ、これで少しレンガの壁にぶつかっています。
追加: コードをステップ実行すると、fetch 呼び出しに到達したときに、「sessionData」オブジェクト内の属性がまったく更新されていません。オブジェクトは、fetch メソッドが実行される前とまったく同じです。
更新: 私が最初にこれを書いて以来、Fiddler から確認できる限り、コードは呼び出しをまったく停止しました。これは以前は機能していましたが、現在、エラーが何であるかを示すことなく、目に見えないほど失敗しているようです。API コードをデバッグすると、サービスの GET メソッドに対する呼び出しがまったく行われていないことがわかります。
さらに更新: エラー/成功のコールバックを削除する以外にコードを変更することなく、これは機能し始めました (一種の)。fetch 呼び出しの後にブレークポイントを配置すると、完全に正常に動作します (Fiddler で確認できることから、成功コールバックが配線されていないため、アプリを確認できません)。ブレークポイントを削除すると、部分的に失敗するようになりました (Fiddler の赤い円ですが、200 応答)。
これはある種の競合状態のようですか?
textStatus を使用するために「完全な」コールバックを使用して情報を取得しようとしましたが、「エラー」と表示されるだけで、特に役に立ちません!