我是网络编程新手。以前我在 java 模块中工作。我想通过点击特定的 url 来获得 http 响应。我正在寻找 w3c 学校,但我尝试仍然没有结果。请帮助我,我想要完整的网页来源。
代码:
<html>
<head>
<script src="jquery.js">
</script>
<script>
var response = '';
$.ajax({ type: "GET",
url: "http://www.google.com",
async: false,
success : function(text)
{
response = text;
}
});
alert(response);
</script>
</head>
<body>
<input type="button" value="submit" />
<p>hello how are you </p>
</body>
</html>
最佳答案
来自 JQuery ajax 方法 documentation :
由于浏览器安全限制,大多数“Ajax”请求都受到同源策略的约束;该请求无法成功从不同的域、子域、端口或协议(protocol)检索数据。
关于javascript - 如何使用 jquery 或 javascript 获取 http 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22630771/