我当前的变量'theurl'具有给定的静态URL。我想通过变量传递URL。主要问题是我想要的URL是通过在单独的网站上输入值来创建的。有没有办法以这种方式检索URL还是完全可怕?
我要从中检索生成的URL的网站是https://cloud.timeedit.net/ltu/web/schedule1/ri1Q7.html#
从那里我在下拉菜单旁边的搜索字段中输入代码“ A0033H”,并选择了“ kurs / program”(瑞典语)。
此刻,我已经检查出两个html页面之间的传递值。
<script type="text/javascript">
var HttpClient = function () {
this.get = function (aUrl, aCallback) {
var anHttpRequest = new XMLHttpRequest();
anHttpRequest.onreadystatechange = function () {
if (anHttpRequest.readyState == 4 && anHttpRequest.status == 200)
aCallback(anHttpRequest.responseText);
}
anHttpRequest.open("GET", aUrl, true);
anHttpRequest.send(null);
}
}
var theurl = 'https://cloud.timeedit.net/ltu/web/schedule1/ri166XQ2505Z5YQv250132Z6yQY820653YX5Y3gQ3076757.json';
var client = new HttpClient();
client.get(theurl, function (response) {
var response1 = JSON.parse(response);
//alert(response);
var test = JSON.stringify(response);
var test2 = test.replace(/,/g, " ");
var test3 = test2.replace(/}/g, " ");
var test4 = test3.replace(/{/g, " ");
var test5 = test4.replace(/"/g, " ");
var test6 = test5.replace(/ /g, " ");
var test7 = test6.replace(/\\/g, " ");
var test8 = test7.replace(/ \ /g, " ");
var test9 = test8.replace(/\ /g, " ");
var test10 = test9.replace(/]/g, " ");
var test11 = test10.replace(/\[/g, " ");
var test12 = test11.replace(/" "/g, '');
//alert(test12);
// this is the string variable
var wordLength = test12.length; // we use the length method to store the length of the word string in a variable
document.write('<table>');
document.write('<tr><th>Lektioner</th></tr>');
for (i = 0; i < wordLength; i++) {
var indexNr = test12.indexOf('id', i += 100);
var indexNr2 = test12.indexOf('id', i += 200);
//alert(indexNr);
//alert(indexNr2);
var substring = test12.substring(indexNr, indexNr2);
// alert(substring);
var j = 200;
var indexNr4 = test12.indexOf('columns', j += 110);
var indexNr3 = test12.indexOf('id', j += 110);
var substring2 = test12.substring(indexNr4, indexNr3);
document.write('<tr><td>' + substring + '</td></tr>');
}
document.write('</table>');
});
</script>
产生的结果为我提供了在表中构造为字符串的JSON格式。
我知道这是严格的意大利面条式代码,但是我只是想知道是否可以检索URL?