在jQuery的阿贾克斯分贝编码卡住ISO-8859-9字符集 [英] Stuck at Jquery Ajax Db Encoding for ISO-8859-9 Charset

查看:256
本文介绍了在jQuery的阿贾克斯分贝编码卡住ISO-8859-9字符集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图传递数据通过我的jQuery的应用程序到数据库。我有严重问题的编码。

I am trying to pass data to db via my Jquery application. I have serious problems with encoding.

当前页面编码是ISO-8859-9。我做了我的AJAX页面编码ISO-8859-9,并通过数据阿贾克斯与的contentType:应用程序/ x-WWW的形式urlen codeD;字符集= ISO-8859-9

Current page encoding is iso-8859-9. I've made my ajax page encoding to iso-8859-9 and passing .ajax data with contentType: "application/x-www-form-urlencoded;charset=ISO-8859-9"

它存储İZİN A°ZA°N 与每一个尝试。

It stores İZİN value as Ä°ZÄ°N with every single trying.

是,如果我创建一个PHP页面,并设置编码,头工作?

Is it work if I create a PHP page and set encoding with headers?

PS:我是一个HTML页面上处理数据。处理器页面是一个ASP页面,并使用MSSQL数据库,我猜。我没有访问处理器页面或分贝。刚刚通过邮寄的形式输入数据。

PS: I am processing data on an HTML page. Processor page is an ASP page and using MsSQL db I guess. I don't have access to processor page or db. Just entering data via form post.

İZİN字符和其他一些类似的词是在上WHERE子句其他一些网页使用SQL查询。所以我不能将字符转换为HTML codeS。我必须用I像我。

İZİN word and some other similar words are using for sql query at some other pages on WHERE clauses. So I cannot convert characters into HTML codes. I have to use İ as İ.

感谢您的建议!

推荐答案

应用程序/ x-WWW的形式urlen codeD 没有一个字符集。它只是ASCII字符。指定字符集有不会做任何事情。

The application/x-www-form-urlencoded does not have a charset. It's simply ASCII characters. Specifying charset there will do nothing.

jQuery将正常urlen code您的数据指定

jQuery will normally urlencode your data as is specified:


  1. 恩code为UTF-8

  2. 百分比恩code

所以:

$.post( "test.php", {data: 'İZİN'}); //Shorthand for $.ajax

其实这个职位服务器:

Actually posts this to server:

data=%C4%B0Z%C4%B0N

当您访问 $ _ POST ['数据'] 使用PHP,他们已变成字节( 0xC4B05AC4B04E ),所以他们呼应会给你畸形数据:

When you access $_POST['data'] with php, they have been turned into bytes (0xC4B05AC4B04E), so echoing them will give you malformed data:

header("Content-Type: text/html; charset=ISO-8859-9");
echo $_POST['data'];
// Ä°ZÄ°N

您可以测试这是真的有:

You can test this is true with:

header("Content-Type: text/html; charset=ISO-8859-9");
echo "\xC4\xB0\x5A\xC4\xB0\x4E";
// Ä°ZÄ°N

在PHP你需要它,只要你收到它转换为ISO-8859-9:

In PHP you need convert it to ISO-8859-9 as soon as you receive it:

<?php
header("Content-Type: text/html; charset=ISO-8859-9");
$data =  "\xC4\xB0\x5A\xC4\xB0\x4E"; //$_POST['data'];
$proper = mb_convert_encoding( $data, "ISO-8859-9", "UTF-8" );
echo $proper;
//İZİN

请注意,这只是容易得多,因为它是pretty多的最佳编码和Web喜欢它使用UTF-8无处不在。如果您使用任何其他编码,那么你将不得不在你的脚趾所有的时间。

Note that it's just much easier to use UTF-8 everywhere because it's pretty much the best encoding and the web loves it. If you use any other encoding then you will have to be on your toes all the time.

这篇关于在jQuery的阿贾克斯分贝编码卡住ISO-8859-9字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆