1

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);
        }
        });
    }
2
  • What code are you using to do what you're doing? Ideally we'd like to see the function that loads the separate page, and if it's relevant the html of that separate page that's loaded. Commented Apr 15, 2010 at 0:33
  • do you get the same behaviour in all browsers? Commented Apr 15, 2010 at 1:11

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

5 Comments

i know i can pass the get variables, but once the data is loaded, the content inside is not clickable.
thats not what im trying to do. can we stick to why the links are not clickable?
what is the value of dirval?
load_file('/'); loads a directory, think of this as like ftp, and it displays folders, and when you click on one, it opens up the new directory
So does that mean you want the generated links to pass information back to the load_file function?
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.