NASH
NASH

Reputation: 73

How do i click on a link that loads a html page and then using ajax (without clicking anything) load an external html page?

html with a link to page2.html and when page2.html is loading i want to load inside it with AJAX the content of page3.html. Can someone provide me with a solution? i have tried this but it doesnt work.

//link icon to correspoding link on what we do
$('#websites').click(function() {
    $(this).attr('href', function() {
        $('#loading_content').load('what-we-do.html/istoselides').fadeIn(1000);
    })
});

Thanks so much!

UPDATE

<li id="adv"><a href="what_we_do.html?istoselides">adv</a></li>


<script type="text/javascript">
$(document).ready(function () {
     if (window.location.search == "?istoselides") {
          #('#loading_content').load('what-we-do.html/istoselides').fadeIn(1000);
     }
});

Upvotes: 2

Views: 167

Answers (1)

David Tang
David Tang

Reputation: 93694

You can pass information from page1 to page2 through the href, but not code, so you'll have to set a keyword of some sort, for example in the query string, and let page2 extract this information:

page1.html

<a href="page2.html?loadPage3">Link to Page2</a>

page2.html

<script type="text/javascript">
    $(document).ready(function () {
         if (window.location.search == "?loadPage3") {
              $('#loading_content').load('what-we-do.html/istoselides').fadeIn(1000);
         }
    });
</script>

Upvotes: 2

Related Questions