简体   繁体   中英

jquery, change jqueryui dialog box content from a ajax call in the webpage

jqueryui is used to show a dialog box, then if there is a click the 'dialog_insider' on the dialog box ,not on the flat (correct wording?) webpage , an ajax call will be made. The file in the called through the ajax html:

<div id="dialog" style="border:1px solid green; width:150px; margin:auto;">
    <div class="dialog_insider">this is the dialog</div>
    <!-- end of class dialog_insider-->    
</div>
<!- end of id  dialog-->

jquery:

<script type="text/javascript">    
    $(document).ready(function(){
        $("#dialog").click(function(){

            my_dialog = $(this).clone();
            my_dialog.dialog();
            $(".dialog_insider", my_dialog).click(function(){
                alert("clicked");
                $.post("replace.php",function(response){
                });
            });
        });
    });
</script>

the file replace.php contains:

<script type="text/javascript">
    $(document).ready(function(){
        alert("hi");
        $("dialog_insider",my_dialog).html('4444444');
    });
</script>

I don't get any functionality(ie no alert, no html changing) from the replace.php page

I tried with $("opener.dialog_insider",my_dialog).html('4444444'); , but no result.

What is the solution?

To make javascript from ajax-called page running, you need to apped it to the current document.

And opener won't work when you make an AXAJ call, works only with opened window.

$.post("replace.php", {}, function(response){
    $('body').append(response);
});

JS will execute when you append it, or make eval() ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM