我在Java7.4.1708(核心),CentOS (TM) SE运行时环境(内部版本1.8.0_152-b16)上运行eXist-db 3.6.1。我希望能够在结构如下的persons.xml中的最后一条记录之后添加一条新记录:
<person xml:id="pe0472"> [...] </person>
<person xml:id="pe0473"> [...] </person>我在app.xql中的一个函数中有一个html表单,该函数调用editpers.html中的via data-template来获取数据:
declare function app:newpers($node as node(), $model as map(*), $searchkey as xs:string?)
{
let $surname := doc(concat($config:app-root, '/input/persons.xml'))//tei:listPerson/tei:person[@xml:id=$searchkey]/tei:persName/tei:surname
[...]
return
<div class="container">
<form action="add.html" method="POST">
<div class="form-group">
Surname:<br/>
<input type="text" name="surname" value="{$surname}"/>
[...]
<input class="btn btn-default" type="submit" value="Submit"/>
</div>
</form>
</div>
};表单的提交会发送给add.html,后者通过data-template引用app:addpers函数
declare function app:addpers($node as node(), $model as map(*)) {
let $peid := request:get-parameter('peid', '')
let $surname := request:get-parameter('surname', '')
[...]
let $on-disk := doc(concat($config:app-root, '/input/persons.xml'))
let $insert := update insert
<person xml:id="{$peid}" >
<persName xmlns="http://www.tei-c.org/ns/1.0">
<surname>{$surname}</surname>
[...]
</persName>
</person>
following $on-disk//tei:person[@xml:id][last()]
return
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Added</title>
</head>
<body>
<div>
<h3>Success!</h3>
</div>
</body>
</html>
};我得到了一个很好的消息,如果我在oXygen中打开主persons.xml文件,我可以看到新记录被很好地添加了。然而,它没有出现在我的网页上,我的网页通过这个查询显示了所有的记录:
declare function app:listPers($node as node(), $model as map(*)) {
for $person in doc(concat($config:app-root, '/input/persons.xml'))//tei:listPerson/tei:person
return
<tr>
<td>{$person/tei:persName/tei:forename}</a></td>
</tr>
};这将显示所有记录,但不是通过app:addpers函数添加的最新记录。刷新浏览器上的缓存,这在我使用以下命令更新现有记录的值时很有帮助:
let $update := update value $on-disk//tei:person[@xml:id eq $peid]/tei:persName/tei:surname with $surname(编辑后的记录在我清除缓存之前不会显示)这次没有帮助。
为了在我的前端(app:listPers)上显示新记录,只需对oXygen中的主文件做一些愚蠢的操作(例如,在任意位置添加和删除一个空间,然后保存它),新记录就会神奇地出现在我的浏览器页面上。这是预期的行为吗?我发现这非常令人费解,我想不出其他任何我可以尝试解决这个问题的方法。
我已经在Firefox 58.0.1和Safari11.0.3上进行了测试。
发布于 2018-02-08 17:49:09
目前,我的解决方法是添加一个
<script type="text/javascript">
window.addEventListener('load', function (e) {
window.applicationCache.addEventListener('updateready', function (e) {
window.location.reload(true);
}, false);
console.log("loaded");
}, false);
</script>到受影响页的头部,这将强制对页进行无缓存重新加载,而不必手动执行。
https://stackoverflow.com/questions/48626865
复制相似问题