现在的位置: 首页 > 综合 > 正文

iPhone Ajex multipart boundary charset

2013年09月12日 ⁄ 综合 ⁄ 共 1274字 ⁄ 字号 评论关闭

 

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 with

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 />";

} ?>

 

抱歉!评论已关闭.