【问题标题】:jQuery ajax doesn't send a responsejQuery ajax 不发送响应
【发布时间】:2020-07-25 14:29:40
【问题描述】:

我将数据发送到特定的 URL,然后我尝试使用 ajax 获取它,它只会打印一个 error

<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)

【问题讨论】:

  • 你得到的错误是什么?
  • @L0uis 我链接了它我什至无法理解错误这有点奇怪 {readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, ...} 这是主要的部分,如果它告诉你一些事情
  • 还不完全确定,做一些研究。但是,您能否确认您不需要在ajax({ ... url: "127.0.0.1/computers{{id}} ... }); 中传递本地主机。我在问,因为它可能是您的浏览器认为它打开一个带有 /computers/{{id}} 的本地目录。
  • @zerecees 这实际上是我的 ipv4(我隐藏了它)我认为这并不重要我可以在“网络”选项卡中看到发布请求
  • 明白了。好吧,我还在谷歌搜索。给我几个。希望我能得到一些具体的东西。我也不明白这个错误。

标签: javascript python jquery ajax post


【解决方案1】:

问题是我没有发送任何数据,但我也在输入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);
    }
    });

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-23
    • 2012-04-24
    • 1970-01-01
    • 2017-06-09
    • 1970-01-01
    相关资源
    最近更新 更多