Saman Ray
Saman Ray

Reputation: 115

HTML onclick behaviour not working properly

I have the following HTML code:

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

and I have the following JavaScript code:

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

I am passing the value of response to HTML id "myText". However, it is not showing me any output. Why is that?

edit: I have added the full code.

Upvotes: 0

Views: 70

Answers (3)

nadun
nadun

Reputation: 61

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

There are two response in your code which might be the confusion. rename one response to some other name. since "function(response)" is the response returning from the server.

Or either directly call like this:

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

finally, is there any response returning from the server?

Upvotes: 1

jamal mehmood
jamal mehmood

Reputation: 1

this will work for you. var HttpClient = function() { //Some code }; this line was causing problem

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

Upvotes: 0

Eugene Ogongo
Eugene Ogongo

Reputation: 375

On the HTML you are calling getinfo() <button onclick="getinfo()">Click me</button>

while its suppose to be getData(). So I think the correct way would be <button onclick="getData()">Click me</button>

Upvotes: 0

Related Questions