Python JSON数据从JS到flask返回无

Python JSON数据从JS到flask返回无,python,flask,Python,Flask,background.js: let data = {'content': 'sample data'}; let xhr = new XMLHttpRequest(); xhr.open("POST", "localhost:5000/test", true); xhr.setRequestHeader("Content-type", "application/json"); xhr.onreadystatech

background.js:

let data = {'content': 'sample data'};

let xhr = new XMLHttpRequest();
xhr.open("POST", "localhost:5000/test", true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.onreadystatechange = function() {
  if (xhr.readyState == 4) {
      console.log('xhr response: '+ xhr.responseText);
  }
}
xhr.send(data);
route.py:

@blueprint.route('/test', methods=['GET', 'POST'])
def test():
    if request.method == 'POST':
        print(request.get_json()) 
        return 'OK', 200
    elif request.method == 'GET':
        print(request.get_json()) 
manifest.json:

{
    "manifest_version": 2,
    "name": "To be named",
    "description": "This extension helps...",
    "version": "0.1.0",
    "permissions": [
        "identity",
        "identity.email",
        "https://localhost:5000/test"
    ],
    "background": {
        "scripts": ["background.js"]
    },  
    "content_scripts": [{
        "matches": ["<all_urls>"],
        "js": ["content.js"],
        "css": ["styles.css"]
    }]
}
改变


事实上,我也尝试过,得到了相同的结果。如果您尝试内容类型而不是内容类型,则同样无效:(
TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.
xhr.send(data);
xhr.send(JSON.stringify(data));