john morris
john morris

Reputation: 31

jquery load links not clickable

ok i am loading a separate page with links in it, into a page named index.php. it loads fine, but when i click one of the links inside the loaded content, nothing happens. they dont act as links. but if i do a alert('hi'); after the load('page.html'); then it will work. any ideas on getting this to work without alerting something after it loads? oh also i cant use a callback, unless there is a way to update the get variable because the page loading, has a $_GET variable, and the links inside the loaded page are supposed to update the $_GET variable. anyways is there a way to make the links clickable after loading the page?

    function load_file(dirval) {
        $.ajax({
        url: "data.php",
        data: {dir: dirval},
        success: function(data) {
            $('#remote-files').html(data);
        }
        });
    }

Upvotes: 1

Views: 715

Answers (2)

Augusto
Augusto

Reputation: 809

I see in your question that you had problems using the load function. However, in your code you are using $.ajax.

For dynamically loading fragments of a page, load() should be the way to go, since it parses the content of the retrieved document, and renders it correctly. If you are using $.ajax in the way depicted in the other answer, jQuery will output the content without any kind of stripping, which is not desired.

Please, consider adding the content of the page you're trying to load, and the updated code you're using.

Take a look at the post in my blog about this function http://arecordon.blogspot.com.ar/2014/01/jquery-load-explained.html

Upvotes: 0

Jonathan
Jonathan

Reputation: 5993

http://api.jquery.com/load/ - has an example of what you're trying to do.

You should be able to pass data on the query string.

Example index.php

<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">

    $(document).ready(function() {
    function load_file(dirval) {
        $.ajax({
            url: "data.php",
            data: {dir: dirval},
            success: function(data) {
                $('#data').html(data);
            }
        });
    }

    load_file('http://mysite.com');
    });

</script>
</head>
<body>
<div id="data"></div>
</body></html>

data.php

<html>
<head>
</head>
<body>
<ul>
    <li><a href="<?php echo $_GET['dir'] ?>/link.html">Link </a></li>
</ul>
</body>
</html>

Upvotes: 1

Related Questions