0

A user using the chat system will report an issue, this will be sent to RestDB and as an admin when you log in to get these reports. I'm using the Ajax GET function on RestDB to call these reports back and display them in the 'display Vals' section. I have been trying different things. I keep getting the "Uncaught SyntaxError: Unexpected token o in JSON at position 1" error. I have a screenshot of this included below. Just wondering if anyone could guide me as to where I'm going wrong? Previously I didnt have the loop included and just had var string = JSON.parse(response); along with document.getElementById('displayVals').innerHTML = x; This wouldn't throw the error but the results would display as undefined.

<script>
export default{
    methods:{
        reportsMethod(){

            var x = document.getElementById("report");
            console.log(x);
            var button = document.getElementById('reportBtn').addEventListener('click', () => {
            /* once everything is ok, post info to report db*/
            this.$f7.dialog.alert('Report: ' + x +'<br>Sucessfully gotten ');

            var settings = {
            "async": true,
            "crossDomain": true,
            "url": "https://yoururl",
            "method": "GET",
            "headers": {
            "content-type": "application/json",
            "x-apikey": "xxxxxxxxxxxxxxxxxxxxx",
            "cache-control": "no-cache"
            }
        }

            $.ajax(settings).done(function (response) {
             console.log(response); 
             var string = JSON.parse(response);

            // for(var i = 0; i < string.length; i++){
            //  var x = string[i];
             document.getElementById('displayVals').innerHTML = string;
            //  }
            });
        });
    }
    }
}
  </script>
            

Error: enter image description here

1 Answer 1

0

You have syntax errors in your code. The code have extra curly braces at the end.

You can count the number of start and end braces in your editor. Then you will find out if it have any inconsistent braces.

Sign up to request clarification or add additional context in comments.

2 Comments

Some of the code didnt paste over sorry, ill update it now
What does the response return inside done function? And also, add .fail() to catch any error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.