我想从网页中检索数据,然后将其显示在我的网页上,没有什么花哨的atm只是显示它,所以它可以读取,但我不知道如何做到这一点,这是我迄今为止(也对不起,如果我不这样做的格式正确我仍然新本):XMLHttpRequest可以获取数据在网页上显示
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title> Night Out In Glasgow!!</title>
<link rel="stylesheet" type="text/css" href="StyleSheet.css">
<script src="pull.js"></script>
</head>
<body>
<form action = "">
<p><button type = "button" onclick ="getData()">Get The Data</button>
</p>
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</body>
这是那么我的JS是在一个名为拉一个单独的文件。 js,我已经链接到我的HTML,希望这可以消除任何混乱形式的原始帖子。
/*jslint node: true, browser: true */
"use strict";
/*jslint node: true, browser: true */
"use strict";
function getData(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST","http://ratings.food.gov.uk/OpenDataFiles/FHRS776en- GB.xml");
xmlhttp.onreadystatechange = checkData;
xmlhttp.send(null);
function checkData() {
if(xmlhttp.status == 4){
if(xmlhttp.status == 200){
//We've got a response
alert(xmlhttp.responseXML);
}
}
else{
//Somethings went wrong
alert("Error: " + xmlhttp.status + ": " +xmlhttp.statusXML);
}
}
}
您的JavaScript需要在''标签。 – Bardicer
这是格式化在这里吗?如果是这样的提示,我会记住,如果它关于实际的代码,我有他们在不同的文件,并引用JS使用 – CallumRob
你有什么尝试,doesn不工作?你知道如何使用Javascript将元素插入DOM吗?或者你没有从Ajax调用中获取数据?如果你能够使用它,JQuery可能有助于简化你的代码。 – Phil