2

YUI3 IO Utility を使用して、ファイルを含むフォームを送信しています。サーバーからの応答には HTML が含まれていますが、要求オブジェクトでアクセスすると取り除かれます。

var form = Y.one('form');
Y.io(form.get('action'), {
    method: form.get('method'),
    form: {
        id: form,
        upload: true
    },
    on: {
        complete: function(id, request) {
            // The server returns a response like <div>response</div>
            console.log(request.responseText); 
            // All HTML is stripped so it just prints 'response' to the console
        }
    }
});

これはデフォルトの動作と見なされますか? 完全な応答コンテンツを取得できないとはほとんど信じられません...サーバーはコンテンツタイプヘッダーも適切に「text/html」に設定します。

どんな助けでも大歓迎です!ありがとうございました!

4

2 に答える 2

1

YUI3のソースコードを見たところです。https://raw.github.com/yui/yui3/master/src/io/js/io-upload-iframe.jsのリクエストオブジェクトを担当する数行は次のとおりです。

_uploadComplete: function(o, c) {
    var io = this,
        d = Y.one('#io_iframe' + o.id).get('contentWindow.document'),
        b = d.one('body'),
        p;

    if (c.timeout) {
        io._clearUploadTimeout(o.id);
    }

    try {
        if (b) {
            // When a response Content-Type of "text/plain" is used, Firefox and     Safari
            // will wrap the response string with <pre></pre>.
            p = b.one('pre:first-child');
            o.c.responseText = p ? p.get('text') : b.get('text');
            Y.log('The responseText value for transaction ' + o.id + ' is: ' +     o.c.responseText + '.', 'info', 'io');
        }
        else {
            o.c.responseXML = d._node;
            Y.log('The response for transaction ' + o.id + ' is an XML     document.', 'info', 'io');
        }
    }
    catch (e) {
        o.e = "upload failure";
    }

    io.complete(o, c);
    io.end(o, c);
    // The transaction is complete, so call _dFrame to remove
    // the event listener bound to the iframe transport, and then
    // destroy the iframe.
    w.setTimeout( function() { _dFrame(o.id); }, 0);
},

したがって、応答に「body」ノードが含まれるとすぐに、bodyコンテンツが「text」として返されます。

o.c.responseText = p ? p.get('text') : b.get('text');

私見では、bodyノードがある場合、innerHTMLを取得する機会はありません。ボディノードのinnerHTMLで「responseHTML」と呼ばれる追加のプロパティを追加するカスタマイズされたIOUploadIframeモジュールを作成することにしました。

あなたはPastebinからソースを得ることができます:http://pastebin.com/WadQgNP2

于 2012-12-21T17:49:48.967 に答える
0

http://yuilibrary.com/yui/docs/io/#the-response-object

プロパティには、responseXML探しているものが含まれている可能性があります。それでも問題が解決しない場合は、デバッガー (Firebug など) でプロパティを変更console.log(request.responseText);console.log(request);て調べ、必要なデータを含むものを見つけてください。

一般に、呼び出されたすべてのプロパティは...Text、XML コードが完全に取り除かれた何かのテキスト コンテンツのみを返すことに注意してください。

于 2012-12-21T17:31:29.963 に答える