如何点击加载html页面然后使用ajax(不点击任何内容)加载外部html页面的链接?

时间:2022-10-12 17:59:21

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.

带有page2.html链接的html,当加载page2.html时,我想用AJAX加载page3.html的内容。有人能为我提供解决方案吗?我试过这个,但它不起作用。

//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);
     }
});

1 个解决方案

#1


2  

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:

您可以通过href将信息从page1传递到page2,但不能传递代码,因此您必须设置某种关键字,例如在查询字符串中,并让page2提取此信息:

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>

#1


2  

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:

您可以通过href将信息从page1传递到page2,但不能传递代码,因此您必须设置某种关键字,例如在查询字符串中,并让page2提取此信息:

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>