https://github.com/evilpie/senddata
https://github.com/evilpie/senddata
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/evilpie/senddata
- Owner: evilpie
- Created: 2010-07-30T20:09:56.000Z (almost 16 years ago)
- Default Branch: master
- Last Pushed: 2010-08-08T21:06:13.000Z (almost 16 years ago)
- Last Synced: 2025-01-22T18:28:06.363Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 97.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
SendData
========
SendData is an Class modleded after FormData to make this functionallity aviable in FireFox 3.5.
The main usefull part is sending files, this feature requires the FileReader.
Example
------
var xhr, sd, fd;
xhr = new XMLHttpRequest;
xhr.open('POST', '/upload.php', true) // You need to use post requests
if ('FormData' in window) { // use native FormData if possible
fd = new FormData();
fd.append('foo', 'bar');
fd.append('answere', 42);
fd.append('file', document.getElementById('input_file').files[0]); //
xhr.send(fd);
}
else {
sd = new SendData();
sd.append('foo', 'bar');
sd.append('answere', 42);
sd.append('file', document.getElementById('input_file').files[0]);
sd.send(xhr) // Attention!
}
Remarkes
-------
SendData internally sets three Request Headers: "Content-Type", "Connection" and "Content-Length"
Methods
-------
SendData#append(name, value)
name: the name of the field, its basically the same as for example the name of an input field
value: can be anything, but File Objects get special treatment
SendData#send(XMLHttpRequestInstance)
XMLHttpRequestInstance: Where the data should be written to
Properties
----------
SendData#onerror = function (message) { }
Assign your handler to this, if you want to get messages when reading a file fails.
Static Method
-------------
SendData.fromForm(form)
form: a html form element
This function is similiar to Mozillas Form#getFormData, and will return a new SendData instance.
Exclaimer
--------
This is my first javascript class i ever wrote, to i would be really happy to get some feedback.