dqwh1202
2015-11-10 10:44
浏览 116
已采纳

为什么angular $ http将datetime字符串转换为unix时间戳?

I have a PHP file which is retrieving value, id and time. Below is an example of the output of the PHP file when accessed directly:

//Using this 
$print($json_encode($data))

//Returns this
"data":[  
  {  
    "y":7.76,
    "x":"2015-05-04 01:23:37",
    "CoilId":"E5E001B11"
  }
]

Now when I use my factory method "getData" to retrieve the data and console log it, I end up with this:

"data":[  
  {  
    "y":7.76,
    "x":1444017905000,
    "CoilId":"E5E001B11"
  }
]

Here is my factory:

myApp.factory('Widget', ['$http', function($http) {

var promise;

return{

    getData: function(widgetType, widgetId, machineId, start, end){
        promise = $http({
          url: "angular/data/testData.php",
          method: "POST",
          headers: {'Content-Type': 'application/x-www-form-urlencoded'},
          data:  $.param({widgetType: widgetType, widgetId: widgetId, 
                         machineId: machineId, start: start, end: end })
        })
        .success(function(data, status, headers, config) {
          console.log(data);
        })
        .error(function(data, status, headers, config) {
          console.log("Data: " + data + "
" + "Status" + status + "
"+ "Headers"
                       + headers + "
" + "Config" + config + "
");
        });

        return promise;
    },

};

}]);

图片转代码服务由CSDN问答提供 功能建议

我有一个PHP文件正在检索值,id和时间。 下面是直接访问时PHP文件输出的示例:

  //使用此
 $ print($ json_encode($ data))
 
 /  /返回此
“数据”:[
 {
“y”:7.76,
“x”:“2015-05-04 01:23:37”,
“CoilId”:“E5E001B11”\  n} 
] 
   
 
 

现在当我使用工厂方法“getData”检索数据并控制台记录它时,我最终得到了这个:

 “data”:[
 {
“y”:7.76,
“x”:1444017905000,
“CoilId”:“E5E001B11”
} 
]  
   
 
 

这是我的工厂:

  myApp.factory('Widget',['$ http',  function($ http){
 
var promise; 
 
return {
 
 getData:function(widgetType,widgetId,machineId,start,end){
 promise = $ http({
 url:“angular  /data/testData.php",n方法:“POST”,
标题:{'Content-Type':'application / x-www-form-urlencoded'},
 data:$ .param({widgetType  :widgetType,widgetId:widgetId,
 machineId:machineId,start:sta  rt,end:end})
})
 .success(function(data,status,headers,config){
 console.log(data); 
})
 .error(function(data,status)  ,header,config){
 console.log(“数据:”+数据+“
 
”+“状态”+状态+“
 
”+“标题”
 +标题+“
  
“+”配置“+ config +”
 
“); 
}); 
 
返回promise; 
},
 
}; 
 
}]); 
    
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doqs8936 2015-11-10 12:27
    已采纳

    Bit of weird one here, but it turns out that this only seems to happen in chrome. This was a subset of a larger issue which has now been resolved. (It was to do with date formatting in different browsers, including phantomjs)

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题