我一直在做很多研究,但找不到办法解决这个问题.我正在尝试从https服务器执行jQuery ajax调用到运行带有自定义自签名证书的jetty的locahost https服务器.我的问题是我无法确定响应是拒绝连接还是不安全响应(由于缺少证书接受).有没有办法确定两种情景之间的差异?的responseText
,并且statusCode
总是在这两种情况下是相同的,即使在Chrome控制台我可以看到一个区别:
net::ERR_INSECURE_RESPONSE
net::ERR_CONNECTION_REFUSED
Run Code Online (Sandbox Code Playgroud)
responseText
总是""并且statusCode
对于两种情况总是"0".
我的问题是,如何确定jQuery ajax调用是否因为ERR_INSECURE_RESPONSE
或由于ERR_CONNECTION_REFUSED
?而失败?
一旦证书被接受,一切正常,但我想知道本地主机服务器是关闭,还是启动并运行,但证书尚未被接受.
$.ajax({
type: 'GET',
url: "https://localhost/custom/server/",
dataType: "json",
async: true,
success: function (response) {
//do something
},
error: function (xhr, textStatus, errorThrown) {
console.log(xhr, textStatus, errorThrown); //always the same for refused and insecure responses.
}
});
Run Code Online (Sandbox Code Playgroud)
即使手动执行请求,我也会得到相同的结果:
var request = new XMLHttpRequest();
request.open('GET', "https://localhost/custom/server/", true);
request.onload = function () {
console.log(request.responseText);
};
request.onerror = function () {
console.log(request.responseText);
};
request.send();
Run Code Online (Sandbox Code Playgroud) 我有一个使用Pagespeed与NGINX一起运行的网站,以便缩小和连接Javascript资源,我需要的(如果可能的话,使用Pagespeed)是为缩小的结果添加横幅和页脚,例如Grunt:
Grunt文件配置代码段:
concat: {
scripts: {
options: {
banner: "(function(){",
footer: "}());"
},
src: ['src/app/app.module.js', 'src/app/components/**/*.js', 'src/app/shared/**/*.js'],
dest: 'dist/scripts/app.min.js'
},
vendor: {
src: ['src/assets/js/vendor/**/*.js'],
dest: 'dist/scripts/vendor.min.js'
}
},
Run Code Online (Sandbox Code Playgroud)
这可以通过Pagespeed实现吗?我想在同一个私有范围中添加缩小的所有内容:(function(){ //...minified code...}());
我一直在阅读文档,但找不到与此主题相关的任何内容.
我知道大多数OOP语言(如果不是全部)的私有可见性在类的基础上定义隐私,即同一类的不同实例可以访问彼此的私有属性/方法.
我想阻止这一点,我想知道什么是最好的设计/实现,以便在不产生负面性能影响的情况下做到这一点.
例如,我知道我可以实现AOP并使用符号,但这会导致性能下降,因为languange引擎必须创建类的反射并检查注释.所以,基本上,我的问题是,避免同一个类的实例访问彼此的私有方法/属性的最佳方法是什么?
例:
class Product
{
private $_prize;
public function __construct($prize)
{
$this->_prize = $prize;
}
public function calculateDiscount(Product $extraProduct)
{
$extraProduct->_prize = 0; //How to avoid this?
}
}
$productA = new Product(10);
$productB = new Product(25);
$productA->calculateDiscount($productB);
Run Code Online (Sandbox Code Playgroud) 这里发生了什么:
我希望"取消预订"按钮在点击后有一个超时.首次点击它会更改为显示"确认取消"按钮.几秒钟后,它返回"取消预订".
我的控制台给了我:
TypeError: $timeout is not a function
Run Code Online (Sandbox Code Playgroud)
我正在使用AngularJS $ timeout:
控制器:
'use strict';
module.controller('ReservationItemCtrl', ['$scope', '$stateParams', '$RPC',
function($scope, $stateParams, $RPC, $timeout) {
......other stuff.......
......other stuff.......
$scope.toggleCancelReservation = function(reservation) {
reservation.clickedcancel = true;
$timeout(function(){reservation.clickedcancel = false}, 4000);
};
}
]);
Run Code Online (Sandbox Code Playgroud)
模板:
<button ng-show="!reservation.value.deleted && !deleted.value"
class="btn btn-danger"
ng-show="canCancel(reservation)" ng-if="!reservation.clickedcancel" ng-click="toggleCancelReservation(reservation)">
Cancel With Refund
</button>
<button type="button" class="btn btn-danger" ng-if="reservation.clickedcancel == true" ng-click="deleteReservation();" style="margin-top: -4px;">
Confirm Cancellation
</button>
Run Code Online (Sandbox Code Playgroud)
我准确地在第一次点击时切换按钮然后再次点击它会正确取消/删除预订,但如果我在第一次点击后没有做任何事情,那么超时永远不会将其返回到原始按钮.在我的控制台中,$timeout is not a function
由于某种原因我看到了吗?我把它包含在我的控制器中.我错过了什么吗?
我不明白7,8,9行:
var worker = new Worker('doWork.js');
worker.addEventListener('message', function(e) {
console.log('Worker said: ', e.data); // Here it send's the data.
}, false);
worker.postMessage('Hello World'); // Send data to our worker.
//7 self.addEventListener('message', function(e) {
//8 self.postMessage(e.data);
//9 }, false);
Run Code Online (Sandbox Code Playgroud)
做这段代码的是什么?1.什么代码行在第7行触发消息事件?2.在第8行的postMessage中传递了什么数据?3.自我做什么?
请考虑以下代码:
circle.each(function (d) {
//...code
});
Run Code Online (Sandbox Code Playgroud)
我该如何打破循环?是否有一种自然的D3方式来突破每个循环?我的意思是没有国旗如下:
var flag = false;
circle.each(function (d) {
if (flag) return;
if (someCondition) flag = true;
//...code
});
Run Code Online (Sandbox Code Playgroud)
我已经尝试在if语句中返回false但是它没有用(想想也许这会起作用,jquery.each
但我错了):
circle.each(function (d) {
if (someCondition) return false; //Not working
//...code
});
Run Code Online (Sandbox Code Playgroud) 我在 json 中有 html,它已经被编码(通过 c#)到:
{"itemID":6,"GlossaryWord":"ante","GlossaryDescription":"\u003cp\u003e\r\n\t\u003cstrong\u003eUp the ante\u0026nbsp;\u003c/strong\u003e\u003c/p\u003e\r\n\u003cul\u003e\r\n\t\u003cli\u003e\r\n\t\t\u003cstrong\u003eHere\u003c/strong\u003e\u003c/li\u003e\r\n\t\u003cli\u003e\r\n\t\t\u003cstrong\u003eis\u0026nbsp;\u003c/strong\u003e\u003c/li\u003e\r\n\t\u003cli\u003e\r\n\t\t\u003cb\u003esomething\u003c/b\u003e\u003c/li\u003e\r\n\u003c/ul\u003e\r\n","CategoryID":6}
Run Code Online (Sandbox Code Playgroud)
But how would I decode GlossaryDescription in JavaScript/AngularJS so that it displays the html tags like <p>
& <strong>
etc? Thanks as always :)
这是一个cakephp 3.1查询结果,我想直接访问$ data-> items但是我得到一个错误,说找不到关键项,我不想使用funtcion toArray(),因为如果我这样做的话将仅返回'items'=> ...并且我丢失了所有'query'=> ...信息.你能用正确的语法来帮助我获得$ data-> items或$ data - > {'items'} ....
$data = object(Cake\ORM\ResultSet) {
'query' => object(Cake\ORM\Query) {
'(help)' => 'This is a Query object, to get the results execute or iterate it.',
'sql' => 'SELECT Posts_types.id AS `Posts_types__id`, Posts_types.name AS `Posts_types__name` FROM posts_types Posts_types ORDER BY id ASC',
'params' => [],
'defaultTypes' => [
'Posts_types.id' => 'integer',
'id' => 'integer',
'Posts_types.name' => 'string',
'name' => 'string'
],
'decorators' => (int) 0,
'executed' => true,
'hydrate' …
Run Code Online (Sandbox Code Playgroud)