/    Sign up×
Community /Pin to ProfileBookmark

simple ajax question

My question is: I found such a simple ajax script (post in header):

[code=php]<script type=”text/javascript”>
function include(id, file){
var req;
req = new XMLHttpRequest();
req.onreadystatechange = function(){
if (req.readyState == 4){
if (req.status == 200){
document.getElementById(id).innerHTML = req.responseText;
} else {
document.getElementById(id).innerHTML = “There was an error… =(“;
}
}
};
req.open(“GET”, file, true);
req.send(null);
}
</script>[/code]

It’s wrote to put:

[code=php]<script type=”text/javascript”>
include(“div”, “file.php”);
</script>[/code]

in place where content had to be changed.

Let’s say I have to include file “test.html” into DIV with id=”test”. How I should change previous script to make it work?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Annaccond spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...