首页 > 解决方案 > 更新调用丢失配置变量中的日期值

问题描述

您好,我有一个应用程序创建了一个包含 Date 变量的对象。然后将该对象传递给 http 更新函数。不幸的是,除了日期重置为 2018-06-06T04:00:00 而不是添加的实际时间之外,所有内容的更新看起来都很棒。出于测试目的,我使用相同的对象有效负载分别运行更新查询,并且它运行良好,所以我知道不是 api。有什么想法我可能做错了吗?

用于有效负载的 JSON 中的项目:

{"id":10, "name":"test", "description":"测试描述", "startDate":"2018-06-06T23:30:00.000Z", "endDate":"2018-06- 07T02:30:00.000Z"}

代码:

app.config(function($routeProvider, $resourceProvider, $httpProvider) {   
    $httpProvider.defaults.headers.common = {Accept: "application/json, text/plain, */*"};

  //other code to set up routes, also added an interceptor to verify the data been sent, this is where I was able to see the data's Date time is reset.

});



//function to update

function updateObj(item){
    $http.put(urlToApi, item, {headers:{'Content-Type': 'application/json', 'Accept': 'application/json'}})
    .then(function successCallback(response) {
      console.log(response);
     }, function errorCallback(response) {
       console.log("ERROR: " + response);
     });
}

标签: angularjsangularjs-httpangularjs-config

解决方案


推荐阅读