jquery - 将 jquery 与 django Rest api 一起放置

标签 jquery ajax django django-rest-framework

我正在尝试通过 ajax jquery 更新我的数据。

当我使用 api 更新数据时,它可以正常工作。但是当我尝试使用 ajax put 时它不会更新。

$.ajax({
            type: 'PUT',
            url: "/api/attend/" + this.props.id + ".json",
            headers: { 'Authorization': "Token " + token },
            data: JSON.stringify({attend_ts: '2016-07-05T13:44:21.855910Z'}),
            success: (result) => {
                console.log("success")
            },
            error: function (cb) { cb }
        });

数据没有更新,但是jquery在控制台返回成功。

最佳答案

我发现错误,我设置了dataType:

$.ajax({
            type: 'PUT',
            url: "/api/attend/" + this.props.id + ".json",
            headers: { 'Authorization': "Token " + localStorage.token },
            data: {
                report: 'test'
            },
            dataType: "json",
            success: (result) => {
                console.log("success")
            },
            error: function (cb) { cb }
});

报告是我数据库中的一个字段

关于jquery - 将 jquery 与 django Rest api 一起放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38223679/

相关文章:

jquery - 如何处理Jquery数据表中的Ajax 401(未经授权的访问错误)?

ajax - 当 Googlebot 请求 `?_escaped_fragment_=` URL 时,它如何知道网络服务器没有隐藏?

python - django get_or_create 取决于自定义管理器方法的结果

javascript - 什么会导致 html 和脚本在 for 循环的迭代中表现不同?

javascript - 如何在单击事件中查找 jQuery 中的上一个元素?

javascript - 包含/嵌入第三方 javascript 的最安全方法

javascript - 为什么这适用于 Firefox 而不适用于 Chrome 或 IE?

javascript - 反向 jquery 调整大小移位功能

jquery - Backbone 模型 CORS 获取未发送

Django基于模型实例限制ModelForm中ManyToMany字段的选项