views:

132

answers:

3

Hi,

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

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

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

+5  A: 

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
+1  A: 

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

used2could
A: 

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

seengee
I really want to do it the ajax way, thanks anyway ;o)
denisjacquemin