我正在尝试从带有JSONP请求的API获取一些数据,但每次都得到404.我认为我的网址有误,但我可以在Chrome中手动点击网址并获得所需的响应.我的$http.jsonp请求总是出错,console.log在错误回调中出现了404 .
这是发出请求的代码:
$scope.fetchDefaultLabel = function () {
// This code will eventually set the label to the site name when the endpoint field blurs.
// Currently not working properly.
if ($scope.endpoint) {
var baseUrl = $scope.endpoint.split('/')[2];
var siteNameUrl = 'http://' + baseUrl + '/api/sitename.json?callback=JSON_CALLBACK';
console.log(siteNameUrl);
$http.jsonp(siteNameUrl)
.success(function(data, status, headers, config) {
$scope.label = data;
})
.error(function(data, status, headers, config) {
console.log('Data: ' + data);
console.log('Status: ' + status);
console.log('Headers: ' + headers);
console.log('Config: ' + …Run Code Online (Sandbox Code Playgroud) 我有一个gulpfile,应该在缩小代码之前清理我的dist目录.有时,干净的任务仍在运行,同时代码被缩小,导致一些丢失的文件.
是什么导致它这样做?我的理解是,任务的依赖关系将在任务运行之前完成,并且依赖关系只会运行一次,即使它是多个任务的依赖关系.
var gulp = require('gulp');
var gulpLoadPlugins = require('gulp-load-plugins');
var plugins = gulpLoadPlugins();
var del = require('del');
gulp.task('default', ['css', 'js', 'fonts']);
gulp.task('clean', function(cb) {
del(['dist/**'], cb);
});
gulp.task('css', ['clean'], function() {
return gulp.src('style.css')
.pipe(plugins.autoprefixer({
browsers: ['last 2 versions']
}))
.pipe(gulp.dest('dist'))
.pipe(plugins.minifyCss({
noRebase: true,
keepSpecialComments: 0
}))
.pipe(plugins.rename({extname: '.min.css'}))
.pipe(gulp.dest('dist'));
});
gulp.task('js', ['clean'], function() {
return gulp.src('scripts.js')
.pipe(gulp.dest('dist'))
.pipe(plugins.uglify({preserveComments: 'some'}))
.pipe(plugins.rename({extname: '.min.js'}))
.pipe(gulp.dest('dist'));
});
gulp.task('fonts', ['clean'], function() {
return gulp.src('fonts/*')
.pipe(gulp.dest('dist/fonts'));
});
Run Code Online (Sandbox Code Playgroud)
更新: Gulp输出表明清理任务在其他任务启动之前完成,但有时并非所有输出文件都在dist目录中.有时他们是.
[09:47:15] Using gulpfile /Users/raddevon/Documents/projects/AlphaBlog/theme/gulpfile.js …Run Code Online (Sandbox Code Playgroud) 我用自制软件安装了Python.如果我没有弄错的话,which python返回/usr/local/bin/python哪个应该是自制软件安装.当我跑步时python,我明白了
Python 2.7.4 (v2.7.4:026ee0057e2d, Apr 6 2013, 11:43:10)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Run Code Online (Sandbox Code Playgroud)
这告诉我,我仍然使用版本2.7.4而不是2.7.5.如果我然后跑brew upgrade python,我得到Error: python-2.7.5 already installed.
任何人都可以帮我弄清楚这里发生了什么?
我正在尝试为我的数据库对象生成URL.我已经读过我不应该使用URL的主键,并且存根不是这个特定模型的好选择.根据该链接中的建议,我在Python解释器中使用zlib.crc32(),发现值通常会返回负数,而我的URL中不需要这些数字.我应该使用更好的哈希来生成我的URL吗?
更新:我最终使用David提出的按位XOR屏蔽方法,并且它的工作非常好.感谢大家的投入.
我在Spacebars模板中有这段代码:
1.
<select class="form-group">
{{#each choices}}
<option>{{this}}</option>
{{/each}}
</select>
Run Code Online (Sandbox Code Playgroud)
我想重复这个N次,每次增加数量,如下:
1.
<select class="form-group">
{{#each choices}}
<option>{{this}}</option>
{{/each}}
</select>
2.
<select class="form-group">
{{#each choices}}
<option>{{this}}</option>
{{/each}}
</select>
3.
<select class="form-group">
{{#each choices}}
<option>{{this}}</option>
{{/each}}
</select>
Run Code Online (Sandbox Code Playgroud)
我希望能够将N传递给自定义模板标签来处理这个问题(例如{{choices 3}}).这样做有什么好干的方法?我有一个模糊的概念,我可以写一个模板助手,但我不知道从哪里开始.
我的webapp的暂存实例抛出一个错误:
Express
500 TypeError: Object #<EventEmitter> has no method 'hrtime'
at Object.logger [as handle] (F:\approot\node_modules\express\node_modules\connect\node_modules\morgan\index.js:96:28)
at next (F:\approot\node_modules\express\node_modules\connect\lib\proto.js:169:15)
at Object.favicon [as handle] (F:\approot\node_modules\express\node_modules\connect\node_modules\serve-favicon\index.js:54:44)
at next (F:\approot\node_modules\express\node_modules\connect\lib\proto.js:169:15)
at Object.expressInit [as handle] (F:\approot\node_modules\express\lib\middleware.js:30:5)
at next (F:\approot\node_modules\express\node_modules\connect\lib\proto.js:169:15)
at Object.query [as handle] (F:\approot\node_modules\express\node_modules\connect\lib\middleware\query.js:43:5)
at next (F:\approot\node_modules\express\node_modules\connect\lib\proto.js:169:15)
at Function.handle (F:\approot\node_modules\express\node_modules\connect\lib\proto.js:177:3)
at Server.app (F:\approot\node_modules\express\node_modules\connect\lib\connect.js:66:37)
Run Code Online (Sandbox Code Playgroud)
摩根/ index.js中的第96行:
req._startAt = process.hrtime();
Run Code Online (Sandbox Code Playgroud)
这只发生在我们部署到Azure的副本上.我们可以直接在机器上通过节点运行Express服务器,一切看起来都很完美.
我们刚刚开始在最近的部署中遇到此问题.知道从哪里开始寻找?我找不到任何类似的问题来搜索Express或Morgan的Github问题.谷歌也没有帮助.
我已经为下拉菜单编写了一个自定义指令.元素绝对位于相对定位的父元素中,因此我需要获取下拉触发元素的高度,以便移动它下面的实际菜单.触发器是指令元素的子元素.我想避免使用完整的jQuery,而是使用Angular的jqLite.
到目前为止,我的尝试包含一个函数,该函数被添加到指令的链接函数中的范围内(以便有权访问element),但我无法将其链接find()或children()关闭以查找子元素.
我的链接和控制器:
link: function(scope, element, attrs) {
scope.clicked = false;
scope.positionDropdown = function() {
if (!scope.clicked) {
scope.clicked = true;
scope.buttonHeight = element[0].find('button').offsetHeight;
}
}
},
controller: function($scope) {
'use strict';
$scope.menuActive = false;
$scope.toggleMenu = function () {
$scope.positionDropdown();
$scope.menuActive = !$scope.menuActive;
};
}
Run Code Online (Sandbox Code Playgroud)
这应该做的是,首次单击按钮时,buttonHeight应使用元素的高度定义范围变量.相反,我在Chrome开发工具中遇到错误:
TypeError: undefined is not a function
at Scope.scope.positionDropdown (http://localhost:3000/directives/dropdown/dropdown-directive.js:17:57)
at Scope.$scope.toggleMenu (http://localhost:3000/directives/dropdown/dropdown-directive.js:25:28)
at Parser.functionCall (http://localhost:3000/angular/angular.js:10656:21)
at http://localhost:3000/angular/angular.js:18838:17
at Scope.$get.Scope.$eval (http://localhost:3000/angular/angular.js:12518:28)
at Scope.$get.Scope.$apply (http://localhost:3000/angular/angular.js:12616:23)
at HTMLButtonElement.<anonymous> …Run Code Online (Sandbox Code Playgroud) 我正在构建一个WordPress主题(WP SE告诉我这里提出这个问题),但我的页脚小部件区域有问题.除了Recent Posts小部件之外,所有小部件似乎都使用我的CSS正确布局.它似乎使前一个元素的边距加倍.
小部件的大小为其容器的33%.我给每行的三个小部件中的前两个右边距为0.5%(33*3 + 0.5*2 = 100)并使用第n个子选择器给每个第三个小部件0正确填充.
对于大多数小部件而言,这可以很好地工作,就像您可以在实时网站的第一行中看到的那样.在第二行,我将Recent Posts小部件作为第二个元素包含在内.这会在前一个元素的右侧引入额外的边距.
您可以看到Chrome开发工具无法计算此额外的保证金.我在这些截图中突出显示了它和前面的元素以显示它们的边距.
前面的小部件http://dl.dropboxusercontent.com/s/2l6dui7f0zrg9ru/2013-07-11%20at%208.49%20AM.png 最近的帖子小部件http://dl.dropboxusercontent.com/s/s3okkwwgjma4y09/2013-07- 11%20原子%208.59%20 AM.png
任何人都可以告诉我,我可能需要做些什么来纠正这个问题?这会将最近帖子小部件之后的小部件推送到下一行,并且会造成很大的混乱.
如果您想查看问题,请访问http://www.kellyshipe.com/.您还会看到上面的行对于不同的小部件是完美的.
我在Gruntfile中有一个非常简单的grunt-contribu-connect配置.
connect: {
dev: {
base: 'dist'
}
},
Run Code Online (Sandbox Code Playgroud)
任务运行并由我的监视任务保持活动,但是,每当我尝试从此基本目录打开页面时,我得到错误输出而不是所需的页面.
Cannot GET /odds.html
Run Code Online (Sandbox Code Playgroud)
在此图像中,您可以看到我的项目结构.Gruntfile位于项目基础上,odds.html我要打开的dist文件位于相对于该文件夹的文件夹中.

在这里,您可以看到错误以及我试图点击的URI.

我确定我忽略了一些愚蠢的东西,但我看不到它.请帮忙!谢谢.
我正在创建一个测验应用程序。我想显示一个随机问题,获取用户的答案,显示反馈,然后转到另一个随机问题。
我正在使用它发布一个随机问题:
getRandomInt = function(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
};
randomizedQuestion = function(rand) {
// These variables ensure the initial path (greater or less than) is also randomized
var greater = {$gte: rand};
var less = {$lte: rand};
var randomBool = !!getRandomInt(0,1);
var randomQuestion = Questions.find({randomizer: randomBool ? greater : less }, {fields: {body: true, answers: true}, limit: 1, sort: {randomizer: 1}});
// If the first attempt to find a random question …Run Code Online (Sandbox Code Playgroud) javascript ×4
angularjs ×2
meteor ×2
python ×2
collections ×1
css ×1
django ×1
express ×1
gruntjs ×1
gulp ×1
hash ×1
homebrew ×1
jsonp ×1
meteor-blaze ×1
node.js ×1
python-2.7 ×1
spacebars ×1
url ×1
wordpress ×1