我将3个文件放在同一个文件夹中:jquery-1.10.2.js
,info.xml
和info.htm
。
这是我的info.xml
:
<Check>
<Metainformation>
<cash>ABC XYZ</cash>
<Doctor>Dr. Peter Smith</Doctor>
<DoctorID>12345678</DoctorID>
<Quartal>Q22004</Quartal>
<Checkdate>20040404123000</Checkdate>
</Metainformation>
<Patientlist>
<Normal_Patient>
<Unchanged count="123" />
<New count="3" />
<Closed count="2" />
<InTest count="4" />
</Normal_Patient>
<Special_Patient>
<Special_Quantity count="8" />
</Special_Patient>
<Notfound_Patient>
<ABC_available count="9" />
<DEF_available count="7" />
</Notfound_Patient>
<Total old="125" new="126"/>
</Patientlist>
</Check>
这是我的info.htm
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name="Daniel" content="Geneva">
<script language="JavaScript" type="text/javascript" src="jquery-1.10.2.js"></script>
<style type="text/css">
.frame {
font-size: 10pt;
}
.div1 {
margin-right:80px;
margin-left:80px;
}
.table1 {
width: 640px;
margin: 0 auto;
border-collapse: collapse;
font-weight: bold;
}
.table1 td {
vertical-align: top;
padding-left: 6px;
padding-bottom: 5px;
border: 1px solid black;
width: 320px;
}
.table1 tr:nth-child(2) td {
border: none;
}
</style>
</head>
<body>
<div class ='frame'>
<div class='div1'>
<table class='table1' style ='margin-top:20px'>
<tr>
<td>Contract</td>
<td id="cash"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Doctor</td>
<td id="Doctor"> </td>
</tr>
<tr>
<td>Quartal</td>
<td id="Quartal"> </td>
</tr>
<tr>
<td>Test carried out by</td>
<td id="Doctor1"></td>
</tr>
<tr>
<td>Checkdate</td>
<td id="Date"></td>
</tr>
</table>
</div>
</div>
<script>
var xml = "info.xml";
xmlDoc = $.parseXML(xml);
$xml = $(xmlDoc);
$doctor = $xml.find("Doctor");
$id = $xml.find("DoctorID");
var doc = $doctor.text() + "(ID: " + $id.text() + ")";
$("#Doctor").append(doc);
$("#Doctor1").append(doc);
</script>
</body>
</html>
我需要从Doctor
加载DoctorID
和info.xml
,并将其放在字段Doctor
和Doctor1
中。但它不起作用。你能告诉我我在哪里错吗?
答案 0 :(得分:1)
文件打开?
function doStuff() {
return new Promise(function(resolve, reject) {
// do asynchronous stuff
var result = 100;
resolve(result);
});
}
doStuff.then(function(data) { console.log('Im done!', data); });
如果xml在变量中,则需要对其进行处理
function doStuff() {
return new Promise(function(resolve, reject) {
// do asynchronous stuff
var result = 100;
resolve(result);
});
}
(async function() { // async/await only works in async functions.
var data = await doStuff();
console.log('Im done!', data);
})();
function fetchUserWithPosts(userId, callback) {
fetchUser(userId, function(user) {
fetchPostsByUserId(userId, function(posts) {
callback({
user: user,
posts: posts
});
});
});
}