1

I have many html files, of which one is the main html page on which I have many buttons. What I want is to load the content of one file on the main html file in the desired div tag. I dont want a single file to contain whole html text, so I want to separate the html text in different file and load only that part on button click which user clicks.

3 Answers 3

1

Please try to use this code.

<html lang="en">
<head>
<meta charset="utf-8">
<title>load index page</title>
<style>
body{ font-size: 12px; font-family: Arial; }
</style>
<script src="jquery.js"></script>
</head>
<body>
<b>Successful Response (should be blank):</b>
<div id="success"></div>
<b>Error Response:</b>
<div id="error"></div>
<script>
var browser=navigator.userAgent;

alert("ASHIk");
$("#success").load("index.php", function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$("#error").html(msg + xhr.status + " " + xhr.statusText);
}
});

</script>
</body>
</html
Sign up to request clarification or add additional context in comments.

Comments

0

it looks like good work for angular.js. Check this out :

https://docs.angularjs.org/tutorial/step_07

Comments

0

You could load the new HTML file with an ajax call (using JQuery) and send the response into the relevant div.

    $.ajax({
        url: <YourUrl>,
        type: "GET",
        dataType: "html",
        cache: false,
        success: function (data) {
            $('#TargetDiv').replaceWith($(data));
        }
    }

1 Comment

We dont have any type of server involved in this. There is a normal html page and which should open when the user clicks.

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.