Prototype messes up the multipart Boundary
Original article: https://prototype.lighthouseapp.com/projects/8886/tickets/498-prototype-messes-up-the-multipart-boundary
Reported by Gabriel aubut-Lussier | December 19th, 2008 @ pm
When preparing a multipart/form-data post
The Ajax. Request class, prototype messes up the boundary by appending '; charset = 'whatever the charset is set to (defaults to UTF-8). See example 1.
In order to fix this, one has to manually set the charset inside the Content-Type and then disable the charset. See example 2.
Example 1 (doesn' t work ):
new Ajax.Request("http://myTestSite.com/test.php", { method: 'post', contentType: 'multipart/form-data; boundary=AaB03x', postBody: '--AaB03x/r/nContent-Disposition: form-data; name=/"test/"/r/n/r/ntest/r/n--AaB03x--/r/n', onSuccess: function(transport) { alert(transport.responseText); }, onFailure: function(transport) { alert('failure'); }});
Example 2 (Works ):
new Ajax.Request("http://myTestSite.com/test.php", { method: 'post', contentType: 'multipart/form-data; charset=UTF-8; boundary=AaB03x', encoding: '', postBody: '--AaB03x/r/nContent-Disposition: form-data; name=/"test/"/r/n/r/ntest/r/n--AaB03x--/r/n', onSuccess: function(transport) { alert(transport.responseText); }, onFailure: function(transport) { alert('failure'); }});
Here is the test. php script:
<? PHP foreach ($ _ post as $ key => $ Val ){
echo $key . ": " . $val . "<BR />";
}?>