0

I have a very simple and straightforward code:

Py:

@blueprint.route('/Ajax', methods=['GET', 'POST']) 
def Ajax():                
    Graph1 = [10,10,10,10,10]
    return jsonify(Graph1)

JS

fetch('/Ajax')
.then(function (response) {
  theData = Object.values(response); 
  console.log(theData);
  return theData; 
})

Yet I am getting:

enter image description here

I am not sure why this is the reason.

1
  • 2
    response does not contain the response data ... try fetch('/Ajax') .then(response => response.json()).then(data => here is the data) Commented Nov 19, 2020 at 2:32

1 Answer 1

1

I'm unsure about your Python code but with fetch in js you need to convert the response to json first.

This should work:

fetch('/Ajax')
  .then(response => response.json())  // <--- this has been added
  .then(function (response) {
    theData = Object.values(response); 
    console.log(theData);
    return theData; 
  });
Sign up to request clarification or add additional context in comments.

1 Comment

I have 5 minutes left haha. Definitely will :)

Your Answer

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