Skip to content

Commit

Permalink
Thanks to FroMage for adding support for xml document posts in XHR! a…
Browse files Browse the repository at this point in the history
…lso addresses incorrect XMLHttpRequest constants as noted in http://envjs.lighthouseapp.com/projects/21590/tickets/113-add-support-for-xhrsenddocument
  • Loading branch information
thatcher committed Mar 17, 2010
1 parent c9fdb70 commit 2cc8e59
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
27 changes: 19 additions & 8 deletions src/platform/rhino/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,26 @@ Envjs.connection = function(xhr, responseHandler, data){
}

//write data to output stream if required
if(data&&data.length&&data.length>0){
if ( xhr.method == "PUT" || xhr.method == "POST" ) {
connection.setDoOutput(true);
var outstream = connection.getOutputStream(),
outbuffer = new java.lang.String(data).getBytes('UTF-8');

outstream.write(outbuffer, 0, outbuffer.length);
outstream.close();
if(data){
if(data instanceof Document){
if ( xhr.method == "PUT" || xhr.method == "POST" ) {
connection.setDoOutput(true);
var outstream = connection.getOutputStream(),
xml = (new XMLSerializer()).serializeToString(data),
outbuffer = new java.lang.String(xml).getBytes('UTF-8');
outstream.write(outbuffer, 0, outbuffer.length);
outstream.close();
}
}else if(data.length&&data.length>0){
if ( xhr.method == "PUT" || xhr.method == "POST" ) {
connection.setDoOutput(true);
var outstream = connection.getOutputStream(),
outbuffer = new java.lang.String(data).getBytes('UTF-8');
outstream.write(outbuffer, 0, outbuffer.length);
outstream.close();
}
}
connection.connect();
}else{
connection.connect();
}
Expand Down
10 changes: 5 additions & 5 deletions src/xhr/xmlhttprequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ XMLHttpRequest = function(){
this.aborted = false;//non-standard
};

// it would be nice if these were part of the standard but
// they are not.
// defined by the standard: http://www.w3.org/TR/XMLHttpRequest/#xmlhttprequest
// but not provided by Firefox. Safari and others do define it.
XMLHttpRequest.UNSENT = 0;
XMLHttpRequest.OPEN = 0;
XMLHttpRequest.HEADERS_RECEIVED = 0;
XMLHttpRequest.LOADING = 0;
XMLHttpRequest.OPEN = 1;
XMLHttpRequest.HEADERS_RECEIVED = 2;
XMLHttpRequest.LOADING = 3;
XMLHttpRequest.DONE = 4;

XMLHttpRequest.prototype = {
Expand Down

0 comments on commit 2cc8e59

Please sign in to comment.