473,327 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

AJAX explicitly set the encoding when sending out the post request

I am trying to send request using ajax with some japanese text.
As any of you know XMLHttpRequest is send with utf-8.

I was hoping there is a way to send with different encoding like

var parameters = "metadata=" +
encodeURI(document.getElementById("metadata").valu e);

http_request.onreadystatechange = metadataUpdate;
http_request.open( 'POST', "/servlet/SendJapText", true );
http_request.setRequestHeader( "Content-type",
"application/x-www-form-urlencoded;charset=Shift-JIS" );
http_request.send( parameters );

Thanks in advance.

Jul 27 '06 #1
1 6342


sm************@gmail.com wrote:

var parameters = "metadata=" +
encodeURI(document.getElementById("metadata").valu e);
I would suggest to use encodeURIComponent and not encodeURI (as the
value to be encoded could e.g. contain '=' or '&' meaning with encodeURI
you would get with value 'Kibo&Xibo'
metadata=Kibo&Xibo
while with encodeURIComponent you get
metadata=Kibo%26Xibo
).
http_request.onreadystatechange = metadataUpdate;
http_request.open( 'POST', "/servlet/SendJapText", true );
http_request.setRequestHeader( "Content-type",
"application/x-www-form-urlencoded;charset=Shift-JIS" );
http_request.send( parameters );
If you set the Content-Type request header it is up to your code to
ensure the argument you pass to the send method is properly encoded.
Thus if you want charset=Shift-JIS then you can't use encodeURI
respectively encodeURIComponent as those do not use/support Shift-JIS as
the charset, rather UTF-8.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: NextOne | last post by:
Hi ! Is it possible to send an AJAX XMLHttpRequest using prototype.js API for a multipart/form-data ? I already done parsing form parameters and sending GET/POST request, but does this work...
4
by: H Lee | last post by:
Hi, I'm an XML newbie, and not sure if this is the appropriate newsgroup to post my question, so feel free to suggest other newgroups where I should post this message if this is the case. I'm...
12
by: JMB | last post by:
Hello, I was wondering if anyone knew of any projects extending the inline upload progress bar to utilize an inpage image uploader with bar, without having to refresh or go to a seperate page,...
2
by: dmagliola | last post by:
Hello all, I'm experiencing a problem with ASP.Net for which I can't find a reasonable explanation, or any information. I'm currently developing an application that, through AJAX, asks the...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
2
by: Zeba | last post by:
Hi guys! I'm new to JS / Ajax; I've been trying to do an Ajax call to my Webservice ( I'm using C# for code-behind). I'm not using any of the libraries available. I am sending my CustID to the...
4
by: Mike P2 | last post by:
Hi. To make page downloading quicker, I added GZipStream into the Response filter. My (shortened VB) code snippet from Global.asax looks like this: ............................................ ...
10
by: mouac01 | last post by:
My site uses lots of AJAX requests to PHP files which then retrieves data from MySQL. About 95% of the time the requests complete without issues. Every once in a while a request will hang for...
11
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit (using .net version 3.5) is closed before the Ajax enable controls complete loading, then IE locks up. Does it in both IE7...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.