2

サンプルコードがあります: default.php:

<?php
JHTML::_('behavior.mootools'); /* to load mootools */
$ajax = "
/* <![CDATA[ */
window.addEvent('domready', function() {
    $('start_ajax').addEvent('click', function(e) {
        e.stop(); 
        var url = 'index.php?option=com_xxx&controller=xxx&task=updateAjax&format=raw';
        var x = new Request({
            url: url, 
            method: 'post', 
            onSuccess: function(responseText){
                document.getElementById('ajax_container').innerHTML = responseText;
            }
        }).send(); 
    });
})
/* ]]> */
" ;
$doc = &JFactory::getDocument();
$doc->addScriptDeclaration($ajax);
?>

そしてコードを使用するdefault.php iのコントローラー:

function updateAjax() {
   echo date('Y-m-d D H:i:s');
}

コードを実行するとエラーundefined method JDocumentRaw::addCustomTag()になります。修正方法を教えてください。

4

2 に答える 2

3

これは、通常、コンポーネントへのアクセスに使用する URL の末尾に &format=raw を追加して、「format」パラメーターを「raw」に設定しているためです。これにより、Joomla は標準の JDocument レンダラーの代わりに JDocumentRaw レンダラーを使用するようになります。これを解決するには、次のいずれかを選択します (より適切な方)。

  • リンクされたページの URL から「format=raw」を削除し、別の方法を使用してページを期待どおりに表示します。たとえば、tmpl=component または template=system を URL に追加します。

  • 「フォーマット」が生に設定されているかどうかのチェックを追加します。その場合、スクリプトをまったく追加しません

  • スクリプトを追加するための独自のメソッドを実装する独自の JDocumentRaw クラスを拡張し、format=raw の代わりに format=yourRendererName を使用します。
于 2012-06-13T14:25:12.060 に答える
3

ajaxに使用するjqueryの呼び出しが間違っていると思います:

$document =& JFactory::getDocument();
$document->addCustomTag("call jquery library or script other");

そして、あなたは試してください:

if($document->getType() != 'raw'){
   $document->addCustomTag("call jquery library or script other"); 
}
于 2012-06-13T02:20:29.233 に答える