iPhone Ajex multipart boundary charset

来源:互联网 发布:淘宝发顺丰快吗 编辑:程序博客网 时间:2024/05/22 02:03

 

Prototype messes up the multipart boundary

原文:https://prototype.lighthouseapp.com/projects/8886/tickets/498-prototype-messes-up-the-multipart-boundary

 

Reported by Gabriel Aubut-Lussier | December 19th, 2008 @ 07:21 PM

When preparing a multipart/form-data POST withthe 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 />";

} ?>

 

原创粉丝点击