-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAJAX.php
More file actions
42 lines (41 loc) · 1.21 KB
/
AJAX.php
File metadata and controls
42 lines (41 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<input type='button' id='btn' value='loadViaAjax'/>
<br/>
<br/>
<div id='war'></div>
<div id='loadScript'></div>
<script>
'use strict';
function ajax(){
var xhr;
if(window.XMLHttpRequest){
xhr=new window.XMLHttpRequest()
}else{
xhr=new window.ActiveXObject('Microsoft.XMLHTTP');
};
return xhr;
};
document.getElementById('btn').onclick=function(){
var xhr=ajax();
xhr.onreadystatechange=function(){
if((this.readyState==4)&&(this.status==200)){
document.getElementById('war').innerHTML=this.responseText;
var war=document.getElementById('war').querySelectorAll('script');
for(var v in war){
if(typeof(war[v])=='function'||typeof(war[v])=='number'||typeof(war[v])=='string'){
continue;
}else{
var cr=document.createElement('script');
cr.async=true;
var no=document.createTextNode(war[v].innerHTML);
cr.appendChild(no);
document.getElementById('loadScript').insertAdjacentElement('afterbegin',cr);
document.getElementById('war').querySelectorAll('script')[0].remove();
document.getElementById('loadScript').querySelectorAll('script')[0].remove();
};
};
};
};
xhr.open('post','pageB.php',true);
xhr.send(null);
};
</script>