开发者

from pure javascript to prototypejs

Is there a way to write the following pure javascript in prototypejs

var xhr = new XMLHttpRequest();

xhr.open("POST", "/photos开发者_JAVA技巧?authenticity_token=" + token 
                        + "&photo[name]=" + img.name
                        + "&photo[size]=" + img.size);

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

I did this but I don't know how to upload the bin file

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');
  }
});

thanks


sendAsBinary method is FireFox specific so it is not implemented in the prototypejs library as this library is intended to work cross browser.


Darin Dimitrov is spot on.

However if it's ajax file uploading you're ultimately after i'd suggest yahoo's uploader. Simple example: http://developer.yahoo.com/yui/examples/uploader/uploader-simple-button.html


FYI swfupload is also a solid file uploader that doesnt require any library

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜