Uncaught ReferenceError: data is not defined at HTMLDocument.<anonymous

Uncaught ReferenceError: data is not defined at HTMLDocument.<anonymous

我正在尝试使用 AJAX 在 html 站点上呈现 Json 响应,但我不断收到错误消息:

Uncaught ReferenceError: data is not defined
    at HTMLDocument.<anonymous

Json对问题的回答:

["[53.50119612705815, -1.1270833894501477] -> [53.34474, -3.01101]", "[53.50119612705815, -1.1270833894501477] -> [53.34474, -3.01101]", "[52.04061648544843, -0.6655072691644374] -> [51.90829, -0.5127]", "[52.04061648544843, -0.6655072691644374] -> [51.90829, -0.5127]", "[52.04061648544843, -0.6655072691644374] -> [51.90829, -0.5127]", "[53.50119612705815, -1.1270833894501477] -> [53.42705, -0.94339]"]

Html 文件 AJAX 和 JS:

<div class="'row">
    <div id="test">  
        <h1> Test </h1>
    </div>

</div>
{% endblock %}

{% block js %}

<script>
    $(document).ready(function(){
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: '/network/dispatch_data/',
            data: data,
            success: function(response) {
                 console.log(response);
                 $('#test').append(response.data);
           }
        });
    });
    </script>
{% endblock %}

当我检查浏览器中的元素时,错误指向 data: data 是错误的来源。知道我做错了什么吗?我可以用 json 响应完美地查看 url,但是用 ajax 显示它证明是一个问题

您正在发送 data 作为请求的正文,但首先您必须定义要发送到 API

的对象
<div class="row">
  <div id="test">
    <h1> Test </h1>
  </div>

</div>
{% endblock %}

{% block js %}

<script>
  const data = {
    bar: [1, 2, 3],
    foo: false
  }

  $(document).ready(function () {
    $.ajax({
      type: 'POST',
      dataType: 'json',
      url: '/network/dispatch_data/',
      data: data,
      success: function (response) {
        console.log(response);
        $('#test').append(response.data);
      }
    });
  });
</script>
{% endblock %}