我有以下HTML代码:
Use this connection string at runtime(update destination web.config)
,我有以下JavaScript代码:
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BibTeX Maker</title>
<script src="sidebar.js"></script>
</head>
<body>
<button onclick="getData()">Click me</button>
<span id="myText"></span>
</body>
</html>
我正在将var HttpClient = function() { //some code };
function getData(){
var response = client.get('https://reference-extraction.herokuapp.com/api/references/download?url=' + url + '&document_type=full_paper&reference_style=ensemble&reference_format=bibtex&engine=v1', function(response) {
document.getElementById("myText").innerHTML = response
});
};
的值传递给HTML id response
。
但是,它没有显示任何输出。为什么会这样?
编辑:我已经添加了完整的代码。
答案 0 :(得分:1)
var response = client.get('https://reference-extraction.herokuapp.com/api/references/download?url=' + url + '&document_type=full_paper&reference_style=ensemble&reference_format=bibtex&engine=v1', function(response) {
document.getElementById("myText").innerHTML = response
});
您的代码中有两个响应,可能是混淆。将一个响应重命名为其他名称。因为“功能(响应)”是从服务器返回的响应。
或者直接这样调用:
client.get('https://reference-extraction.herokuapp.com/api/references/download?url=' + url + '&document_type=full_paper&reference_style=ensemble&reference_format=bibtex&engine=v1', function(response) {
document.getElementById("myText").innerHTML = response
});
最后,服务器是否返回任何响应?
答案 1 :(得分:0)
在HTML上,您正在调用getinfo()<button onclick="getinfo()">Click me</button>
,而它应该是getData()。所以我认为正确的方法是<button onclick="getData()">Click me</button>
答案 2 :(得分:0)
这将为您工作。 var HttpClient = function(){//某些代码}; 这条线引起了问题
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BibTeX Maker</title>
<script type="text/javascript">
function getData(){
if (window.location.href.indexOf("pdf") != -1) {
var url = window.location.href;
var client = new HttpClient();
var response = client.get('https://websiteName + url', function(response) {
document.getElementById("myText").innerHTML = response});
} else {
alert("Error: Not a PDF File");
}
}
</script>
</head>
<body>
<button onclick="getData()">Click me</button>
<span id="myText"></span>
</body>
</html>