4

我有一个概念性的 DOM 问题 - 我希望它有意义。

我的页面(称为'Main')上有prototypeJS AJAX Updater,我正在选择要编辑的记录,并将'page B'(部分)调用到'Main'页面上的div中。

当我单击部分中的表单时,它会调用“主”上的函数 - 但是更新程序是“应该”更新部分上的 div ......但它永远不会。我很确定 DOM 找不到它,因为它已被渲染或带入 Main ...

我该如何解决这个问题???

主要的

<script>
// pulls page B into Main div
function getItem( id ) {
    var url = 'itemDetails.php'; 
    var pars = { id:id };
    var myAjaxOpts = new Ajax.Updater( 'itemDetail', url, {
            method:'post'
            ,parameters:pars
            ,evalScripts:true
        });
}

// post form and expects messages in 2 places (1) the upated div (on page B) and the message div on Main
// Only main showing up
function assignItem( frm ) {
    var url = 'assignItem.php'; 
    var pars = Form.serialize( frm );
    var myAjaxOpts = new Ajax.Updater( 'subMessage', url, {
            method:'post'
            ,parameters:pars
            ,evalScripts:true
            ,onSuccess: function( response ){
                //console.log( 'request ready to be made' );
                $( 'mainMessage' ).update( response );
            }
        });
}
</script>   

<!-- page A - Main -->
<div id="mainMessage"></div>
<ul>
    <li><a onClick="getItem( 1 );">item 1</a></li>
    <li><a onClick="getItem( 2 );">item 2</a></li>
    <li><a onClick="getItem( 3 );">item 3</a></li>
</ul>
<div id="itemDetail"></div>
<!-- end page A -->

B页(部分)

<!-- page B - Partial -->
<div id="subMessage"></div>
<form>
    -- edit record ---
<input type="button" onClick="assignItem( this.form );" ></form>
<!-- end page B -->

顺便说一句 - 应该注意这是一个“减少”的样本(可能有错别字),我按预期取回数据,AJAX 没有问题,只是部分中的 div 没有似乎可用于 Main 上的功能。

谢谢

4

1 回答 1

0

只需更改您要更新的ID。

改变这个:$( 'mainMessage' ).update( response );

经过 :$( 'subMessage' ).update( response );

于 2013-05-25T16:10:00.777 回答