我正在使用Angular和$ http请求从服务器获取数据。它在同一个服务器目录中模拟数据,但在20秒内返回响应。这是很长的路要走。该请求在应用程序启动时执行。 我试图使用jQuery $ .ajax执行相同的查询,并且它在10 ms内工作。但我想摆脱jQuery。 为什么AngularJs $ http需要这么长时间?
我正在使用Ifeanyi Isitor's Lazy Loading In AngularJS示例如何使用带角度的require.js。加载我的第一个视图的控制点指向执行查询的服务。在铬开发工具网络traking我看到它需要少10毫秒时获取文件。但使用console.time设置它之前执行查询,并在成功结束它承诺它记录约20000毫秒。可以因为延迟加载吗?但为什么jQuery工作得很快?这里是我的服务代码
define(['appModule'], function(app) {
app.lazy.factory('daoService', ['$http', function($http) {
var ...
...
getChanges = function(tableName, modifiedSince, callback) {
console.log('data access time starts');
console.time('data access time');
// this works in 20000 ms
$http.post(tablesUrl[tableName]).success(function(data) {
console.log("The server returned " + data.length + " changes);
console.timeEnd('data access time');
callback(data);
}).error(function(data){
console.log(data);
});
/* this works in about 10 ms
$.ajax({
url: tablesUrl[tableName],
dataType:"json",
success:function (data) {
console.log("The server returned " + data.length + " changes);
console.timeEnd('data access time');
callback(data);
},
error: function(model, response) {
console.log(response);
}
});*/
},
通常AngularJS是非常快的。请提供一些代码 – tschiela
您的服务器是罪魁祸首。不是角度。 – Abilash
它也可能是锁定在前端的东西。请提供一些代码来帮助 – bdavidxyz