![](/img/trans.png)
[英]How to get the response of an http website withing a string using JavaScript?
[英]How to get http response using jquery or javascript
我是Web编程的新手。以前我在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>
您还可以添加错误回调并对其进行调试。
$.ajax({ type: "GET",
url: "http://www.google.com",
async: false,
success : function(data, textStatus)
{
alert(data);
alert(textStatus);
},
error : function(XMLHttpRequest, textStatus, errorThrown)
{
alert(XMLHttpRequest);
alert(textStatus);
alert(errorThrown);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.