小编Man*_*rio的帖子

使用ajax请求下载文件

我想点击按钮时发送"ajax下载请求",所以我试着这样做:

JavaScript的:

var xhr = new XMLHttpRequest();
xhr.open("GET", "download.php");
xhr.send();
Run Code Online (Sandbox Code Playgroud)

的download.php:

<?
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename= file.txt");
header("Content-Transfer-Encoding: binary");    
readfile("file.txt");
?>
Run Code Online (Sandbox Code Playgroud)

但是没有按预期工作,我该怎么办?先感谢您

javascript php ajax file download

87
推荐指数
5
解决办法
27万
查看次数

仅当flex项目被包装时,margin-top

我有一个带有两个弹性物品的弹性容器.我想在第二个上设置一个margin-top,但只有当它被包裹而不是在第一个flex线时.

如果可能,我想避免使用媒体查询.

我认为第一个元素的边缘底部可能是一个解决方案.但是,当元素没有被包裹时,它会在底部增加空间,所以同样的问题.

这是我的代码:

.container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}
.item-big {
  background: blue;
  width: 300px;
}
.item-small {
  background: red;
  margin-top: 30px;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
  <div class="item-big">
    FIRST BIG ELEM
  </div>
  <div class="item-small">
    SECOND SMALL ELEM
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

css margin flexbox

64
推荐指数
2
解决办法
1万
查看次数

如何检查路径是绝对路径还是相对路径

UNIX绝对路径以'/'开头,而Windows以字母'C:'或'\'开头.node.js是否有标准的多平台函数来检查路径是绝对路径还是相对路径?

javascript directory path absolute node.js

27
推荐指数
3
解决办法
1万
查看次数

在 mongoose 中, model.save 是增量原子还是我应该始终使用 $inc ?

我需要增加 MongoDB 和 mongoose 中记录的 likes 字段,但我对这些操作的原子性有点“担心”,因为这应该是并发安全的:

Post.findById(id, function(err, post) {
  post.update({$inc: {
      likes: 1
  }});
});
Run Code Online (Sandbox Code Playgroud)

Post.findById(id, function(err, post) {
    post.likes++;
    post.save()
});
Run Code Online (Sandbox Code Playgroud)

它们提供相同的安全结果吗?想想我什至必须减少记录的点赞数(例如,如果用户再次单击点赞按钮)

Post.findById(id, function(err, post) {
  post.update({$inc: {
      likes: -1
  }});
});
Run Code Online (Sandbox Code Playgroud)

atomic mongoose mongodb node.js

5
推荐指数
1
解决办法
2719
查看次数

使用AES256和Node.js解密输入数据长于15个字符时出错

我正在使用Node.js的加密模块和AES-256-CBC密码算法编写自己的安全类.

但是当我尝试解密从超过15个字符的输入数据加密的加密字符串时,会出现此错误:

crypto.js:153
var ret = this._handle.final();
Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
Run Code Online (Sandbox Code Playgroud)

我认为问题在于加密或IV生成,事实上,加密的十六进制字符串总是32个字符长.

我们一起审查代码:

var crypto = require("crypto"),
    password = "mySecureKey",
    salt = "mySaltKey";

//generate the IV
crypto.pbkdf2(password , salt, 4096, 8, "sha1", function(err, key) {
    if (err) throw err;   
    var cipher_iv = new Buffer(key.toString('hex'));

    //encrypt the string
    var input = "helloPrettyWorld";
    cipher = crypto.createCipheriv("aes-256-cbc", new Buffer(password), cipher_iv);
    cipher.update(input, "utf8", "hex");
    var encrypted = cipher.final("hex"); //i.e: input = "hello"; encrypted = "2300743605fbdaf0171052ccc6322e96"

    //decrypt the string
    cipher = crypto.createDecipheriv("aes-256-cbc", new Buffer(password), …
Run Code Online (Sandbox Code Playgroud)

encryption cryptography aes node.js

2
推荐指数
1
解决办法
2043
查看次数

在Azure Web App服务中从https重定向到http

我有一个支持HTTP和HTTPS(带有效证书)的网站,但遗憾的是,对于某些外部服务的内部问题,HTTPS配置还没有准备好投入生产.

我想通过IIS(web.config文件)重定向每个https请求到http.

我在官方文档中找到了从http重定向到https而不是反向的代码.所以我试图转换它但IIS实际上没有重定向:

<rule name="Redirect to HTTP" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP}" pattern="^OFF$" />
    </conditions>
    <action type="Redirect" url="http://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)

iis https redirect http azure

1
推荐指数
1
解决办法
2733
查看次数