抱歉:我知道这是一个常见问题解答,但我进行了尝试并没有成功。
我要完成的工作是在“搜索”选项卡中生成Apache Solr结果(完成;正在工作;附加了屏幕截图),然后在“文档”选项卡中打开这些结果(返回的文档标题是到源文档的超链接)(以及更高版本) ,“图形”标签中的实体和文档之间的链接)。
目前,我正在“离线”(本地主机)上工作,但最终我想将此工作推送到在线(虚拟专用服务器)上。
这是示例代码和JS小提琴(https://jsfiddle.net/pfjtgLs6/)
...在此示例中,我将Google作为“结果”标签中链接的示例,我想在“文档”标签中打开该链接。实际上,这些链接(复数)将是文档的标题(即Solr搜索结果),或该选项卡中的其他链接。
我一直在编码一个Ajax解决方案时遇到麻烦,该解决方案通常解决这些链接(再次是复数),而不是将URL硬编码到Ajax方法中。
<!DOCTYPE html>
<html encoding="UTF-8" charset="UTF-8" lang="en-US" language="English" xmlns="https://www.w3.org/1999/xhtml/" itemtype="http://schema.org/WebPage">
<head>
<meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<script type = "text/javascript">
$(init);
function init(){
$("#tabs").tabs();
}
</script>
</head>
<body>
<div id = "tabs">
<ul>
<li><a href="#search">Search</a></li>
<li><a href="#documents">Documents</a></li>
<li><a id="documents2_id" href="#documents2">Documents2</a></li>
<li><a href="#graph">Graph</a></li>
</ul>
<div id="search">
<ul>
<li>search item 1</li>
<li>search item 2</li>
</ul>
<p>How can I open <a href="https://www.google.com/">this link</a> (Google, for example), in the 'Documents' tab? ... Ajax solutions preferred.</p>
<p>Please note that in my project, I am presently working with local files on a localhost webserver; however, I am also interested in comments and suggestions on CORS issues.]</p>
<p><button type="button" onclick='$("#documents2_id").trigger("click");'>
Go to 'Documents2' tab
</button> </p>
</div>
<div id="documents">
<ul>
<li>documents item 1</li>
<li>documents item 2</li>
</ul>
</div>
<div id="documents2">
<ul>
<li>documents2 item 1</li>
<li>documents2 item 2</li>
</ul>
</div>
<div id="graph">
<ul>
<li>graph item 1</li>
<li>graph item 2</li>
</ul>
</div>
</body>
</html>
当使用带有远程内容的选项卡时,最好使用jquery ajax加载数据。这将调用外部网页,然后在.done()函数内部,这会将网页响应附加到tab / div。
$.ajax({
method: "GET",
url: "http://www.example.com/path/to/url",
data: {}
}).done(function( response ) {
$("#documents").html(response);
});
如果您需要调试网页html响应,请在下面使用它。这样,您将能够查看网页网址返回的内容
$.ajax({
method: "GET",
url: "http://www.example.com/path/to/url",
data: {}
}).done(function( response ) {
console.log(response);
});
请注意,大多数开发人员会确保外部网站页面以json格式编写,然后循环搜索结果数组,但这并不总是可能的,特别是如果您不拥有外部网页。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句