-
Notifications
You must be signed in to change notification settings - Fork 0
/
test 1 - retrieving.html
127 lines (116 loc) · 3.79 KB
/
test 1 - retrieving.html
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<script>
var xmlhttp = new XMLHttpRequest();
var url = "test 1 - script.php?page=index";
var totalData;
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
myFunction(xmlhttp.responseText);
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
function myFunction(response) {
var arr = JSON.parse(response);
var i;
var out = "<table>";
totalData = arr.length;
for (i = 0; i < totalData; i++) {
out += "<tr><td>" +
arr[i].ID +
"</td><td>" +
arr[i].display +
"</td><td>" +
arr[i].contentTitle +
"</td><td>" +
//htmlspecialchars_decode(arr[i].content).replace(/['"]+/g, '') +
base64_decode(arr[i].content) +
"</td></tr>";
}
out += "</table>";
document.getElementById("myDiv").innerHTML = out;
}
base64_decode = function(s) {
var e={},i,b=0,c,x,l=0,a,r='',w=String.fromCharCode,L=s.length;
var A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
for(i=0;i<64;i++){e[A.charAt(i)]=i;}
for(x=0;x<L;x++){
c=e[s.charAt(x)];b=(b<<6)+c;l+=6;
while(l>=8){((a=(b>>>(l-=8))&0xff)||(x<(L-2)))&&(r+=w(a));}
}
return r;
};
function htmlspecialchars_decode(string, quote_style) {
// discuss at: http://phpjs.org/functions/htmlspecialchars_decode/
// original by: Mirek Slugen
// improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// bugfixed by: Mateusz "loonquawl" Zalega
// bugfixed by: Onno Marsman
// bugfixed by: Brett Zamir (http://brett-zamir.me)
// bugfixed by: Brett Zamir (http://brett-zamir.me)
// input by: ReverseSyntax
// input by: Slawomir Kaniecki
// input by: Scott Cariss
// input by: Francois
// input by: Ratheous
// input by: Mailfaker (http://www.weedem.fr/)
// revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// reimplemented by: Brett Zamir (http://brett-zamir.me)
// example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
// returns 1: '<p>this -> "</p>'
// example 2: htmlspecialchars_decode("&quot;");
// returns 2: '"'
var optTemp = 0,
i = 0,
noquotes = false;
if (typeof quote_style === 'undefined') {
quote_style = 2;
}
string = string.toString()
.replace(/</g, '<')
.replace(/>/g, '>');
var OPTS = {
'ENT_NOQUOTES': 0,
'ENT_HTML_QUOTE_SINGLE': 1,
'ENT_HTML_QUOTE_DOUBLE': 2,
'ENT_COMPAT': 2,
'ENT_QUOTES': 3,
'ENT_IGNORE': 4
};
if (quote_style === 0) {
noquotes = true;
}
if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
quote_style = [].concat(quote_style);
for (i = 0; i < quote_style.length; i++) {
// Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
if (OPTS[quote_style[i]] === 0) {
noquotes = true;
} else if (OPTS[quote_style[i]]) {
optTemp = optTemp | OPTS[quote_style[i]];
}
}
quote_style = optTemp;
}
if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
string = string.replace(/�*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
// string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
}
if (!noquotes) {
string = string.replace(/"/g, '"');
}
// Put this in last place to avoid escape being double-decoded
string = string.replace(/&/g, '&');
return string;
}
</script>
<body>
<div id="myDiv">
</div>
</body>
</html>