首页 > 解决方案 > jQuery ajax 不发送响应

问题描述

我正在将数据发送到特定的 URL,然后我尝试使用 ajax 获取它,它只是打印一个错误

<script type="text/javascript" src="{{ url_for('static', filename='jquery.js') }}"></script>
<script>
      $(document).ready(function()
    {
    $.ajax({
        method: "POST",
        url: "/computers/{{id}}",
        dataType: "json",
        async: true,
        succsess: function(data){
            var json = $.parseJSON(data); // create an object with the key of the array
            alert(json.html);
            console.log(data)
        },
        error: function(error){
         console.log("Error:");
         console.log(error);
    }
    });
});
</script>

^ 这就是我收到请求的方式(id 为 2)

标签: javascriptpythonjqueryajaxpost

解决方案


问题是我没有发送任何数据,但我也在输入,dataType: "json"所以出错了。

$.ajax({
        method: "POST",
        url: "/computers/{{id}}",
        async: true,
        succsess: function(data){
            var json = $.parseJSON(data); // create an object with the key of the array
            alert(json.html);
            console.log(data)
        },
        error: function(error){
         console.log("Error:");
         console.log(error);
    }
    });

所以这是正确的代码,因为我没有发送任何数据。


推荐阅读