我正在尝试使用 XMLHttpRequest 从有关机构的网站获取数据,但我收到的不是数据而是错误页面,请帮助
我的代码:-
var url = '[https://tsecet.nic.in/institute_details.aspx?iCode=JNTH][3]';
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Typical action to be performed when the document is ready:
document.write( this.responseText);
}
}
xhttp.open("GET", url , true);
xhttp.send();
目标网页地址:- https://tsecet.nic.in/institute_details.aspx?iCode=JNTH
如果我尝试打开
https://tsecet.nic.in/Default.aspx >>然后点击>>
institute profile >> 然后点击>> JNTH
然后我就可以在浏览器中获取数据,否则我会被重定向到错误页面
请帮助我...
注意
I am trying to get this data from a different website and a different domain This website is scripted in aspx
最佳答案
您尝试运行的 AJAX 请求无法执行此操作,因为页面具有 X-XSS-Protection: 1
header blocking such requests 。看起来好像它们只允许内部 URI 在主页设置的“框架”内启动。不幸的是,我不能确定。简而言之,您将需要另一种方法。
关于javascript - 如何从网页中获取文本数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54501386/