JQuery harici yüklenen sayfa için yanıt vermiyor

1 Cevap php

I've been lookings days for solving a problem, but i can not find the trick.. When i load an external php page into a div and click afterward on a link come with the external php code, this link does nothing. Please take a look at this code.

index.php Test

<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function() {


    $("#loadexternfile").bind("click", function(){
        // some more events
        loadContent();
    });

    $("#test").click(function() {
        alert("Hello world!");
    });

    function loadContent() {
        $.ajax({
            type: "GET",
            url: "external.php",
            cache: false,
            dataType: 'html',

            success: function(html){
                $(".loaddiv").html(html);
            },

            error: function(){
            },

            complete: function(){
            }
        });
    }
});
</script>


</head>
<body>

<a href="#" id="loadexternfile">loadexternfile</a>
<div class="loaddiv"></div>

</body>
</html>

external.php

<a href="#" id="test">test</a>

Herhangi bir fikir?

Teşekkürler

1 Cevap

Ne istediğiniz jQuery live() yöntemi kullanmaktır. Bkz http://api.jquery.com/live/, hangi olacak:

"Attach a handler to the event for all elements which match the current selector, now or in the future."

Yani değiştirin:

$("#test").click(function() {
   alert("Hello world!");
});

Için:

$("#test").live('click', function() {
   alert("Hello world!");
});