javascript - 从纯javascript到prototypejs

标签 javascript upload prototypejs

有没有办法在prototypejs中编写以下纯javascript

var xhr = new XMLHttpRequest();

xhr.open("POST", "/photos?authenticity_token=" + token 
                        + "&photo[name]=" + img.name
                        + "&photo[size]=" + img.size);

xhr.overrideMimeType('text/plain; charset=x-user-defined-binary');
xhr.sendAsBinary(bin);

我这样做了,但我不知道如何上传 bin 文件

var url = '/photos';
new Ajax.Request(url, {
  method: 'post',
  parameters: { 
    authenticity_token: token,
    'photo[name]': img.name,
    'photo[size]': img.size       
  },
  onSuccess: function(transport) {
    alert('Yeah');
  }
});

谢谢

最佳答案

sendAsBinary 方法是 FireFox 特定的,因此它没有在 prototypejs 库中实现,因为该库旨在跨浏览器工作。

关于javascript - 从纯javascript到prototypejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2306052/

相关文章:

Javascript防止可拖动div位于父div之外

ios - 应用上传错误 : "The value for key CFBundleVersion must be a period-separated list of non-negative integers"

javascript - 事件 'Window load' 在带有原型(prototype)的 Opera 中不起作用

javascript - 无法使用 Rails 和 Prototype 渲染多条线

javascript - 我们如何在深色背景效果中创建加载窗口

javascript - 使用 javascript 立即获取输入[类型 ="file"] 值?

javascript - 可恢复上传在 Android 后台失败 - React Native

javascript - 如何以 Angular 对姓氏列表进行排序?

Perl CGI 获取多部分/表单数据文件内容,无需临时文件

php - 为什么这个基本的 imagejpeg() 缩放器返回黑色图像?