Ajax 如何向后台提交时间

我们做前后的交互时候,可能涉及到时间的提交,后端接收模型中的时间数据类型为Date类型,所以我们要给后端传的数据为Date类型,但由于方便用户使用,我们往往展示和获取的数据是格式化后的时间格式。

模型类:

Ajax传送格式:

  $.ajax({
            type: "post",
            contentType: "application/x-www-form-urlencoded",
            url: "/api/v1/****",
            data: {

                "ftime": new Date(ftime),
                "title": title,
                "content": content,
                "ltime":  new Date(ltime),

            },
            dataType: "json",
            success: function (data) {
                if (data.resultTypeEnum == 200) {
                    layer.msg(data.message, {icon: 1})
                    clearhomework();
                } else {
                    layer.msg(data.message, {icon: 2})
                }
            }
        });

这里做一个简单的操作,就是把时间再转成Date类型。

发布了67 篇原创文章 · 获赞 139 · 访问量 14万+

猜你喜欢

转载自blog.csdn.net/qq_37857921/article/details/104892681