IPhone ajex multipart boundary charset

Source: Internet
Author: User
Tags php foreach

 

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

}?>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.