HTML onclick 行为无法正常工作

HTML onclick behaviour not working properly

我有以下 HTML 代码:

<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>

我有以下 JavaScript 代码:

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
    });
};

我正在将 response 的值传递给 HTML id "myText"。 但是,它没有显示任何输出。这是为什么?

编辑:我已经添加了完整的代码。

在 HTML 上你正在调用 getinfo() <button onclick="getinfo()">Click me</button>

而它应该是 getData()。所以我认为正确的方法是 <button onclick="getData()">Click me</button>

这对你有用。 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>
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
    });

您的代码中有两个响应可能会造成混淆。将一个响应重命名为其他名称。因为 "function(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
        });

最后,服务器有没有返回响应?