2

Failed to add HTML file via jquery

 2 years ago
source link: https://www.codesd.com/item/failed-to-add-html-file-via-jquery.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Failed to add HTML file via jquery

advertisements

I know this question has been asked several times but I am experiencing problem with this. I want to append my index.html file with contents of otherpage.html

My code for index.html is

<html>
<head>
    <script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $.get("otherpage.html", function (data) {
                $("#appendToThis").append(data);
            });
        });
    </script>
</head>
<body>
    <div id="appendToThis"></div>
</body>

And my code for otherpage.html is

<p>This is second page.</p>

When I open Index.html I see a blank white page. Can anyone please point out where the mistake is..Thanks in Advance


This is another answered question that I believe is what you are looking for:

How to load another html file using JS

This example uses some of the points others were making in this thread. It will require an AJAX request for the JS to read the file, parse it, and then replace that info. The example uses an onClick method, but you should be able to use any method that you like (including on load) to execute your defined AJAX call function.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK