相关疑难解决方法(0)

jQuery抓取一个用input type ='file'上传的文件

我想抓住<input type='file'>标签上传的文件.

当我执行$('#inputId').val()时,它只获取文件的名称,而不是实际的文件本身.

我试图遵循这个:

http://hacks.mozilla.org/2011/03/the-shortest-image-uploader-ever/

function upload(file) {

  // file is from a <input> tag or from Drag'n Drop
  // Is the file an image?

  if (!file || !file.type.match(/image.*/)) return;

  // It is!
  // Let's build a FormData object

  var fd = new FormData();
  fd.append("image", file); // Append the file
  fd.append("key", "6528448c258cff474ca9701c5bab6927");
  // Get your own key: http://api.imgur.com/

  // Create the XHR (Cross-Domain XHR FTW!!!)
  var xhr = new XMLHttpRequest();
  xhr.open("POST", "http://api.imgur.com/2/upload.json"); // Boooom!
  xhr.onload = …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

是否可以提出安全的JSONP请求?

我只需要支持新的浏览器.

我必须依靠外部服务来提供JSONP数据,我不拥有该服务,并且它不允许CORS.

我不得不相信来自外部服务器的JSONP请求,因为他们可以在我的终端上运行任意代码,这将允许他们跟踪我的用户,甚至窃取他们的信息.

我想知道是否有任何方法可以创建一个安全的JSONP请求?

(相关:如何可靠地保护公共JSONP请求?但不能使用新的浏览器放松)

注意:我问/答答了问答风格,但我对其他想法非常开放.

javascript jsonp

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

标签 统计

javascript ×2

jquery ×1

jsonp ×1