我有一个PHP文件正在检索值,id和时间 em>。 下面是直接访问时PHP文件输出的示例: p>
现在当我使用工厂方法“getData”检索数据并控制台记录它时,我最终得到了这个: p >
这是我的工厂: p>
//使用此
$ print($ json_encode($ data))
/ /返回此
“数据”:[
{
“y”:7.76,
“x”:“2015-05-04 01:23:37”,
“CoilId”:“E5E001B11”\ n}
]
code> pre>
“data”:[
{
“y”:7.76,
“x”:1444017905000,
“CoilId”:“E5E001B11”
}
]
code> pre>
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;
},
};
}]);
code> pre>
div>
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;
},
};
}]);