2

i want to store chinese characters from an html page into oracle database using ajax concept.

Front end : HTML & PHP.
Back end  : Oracle 11G.

Oracle Characteristics:

NLS_LANGUAGE = AMERICAN
NLS_CHARACTERSET = AL32UTF8
NLS_NCHAR_CHARACTERSET = AL16UTF16

The above characteristics cannot be changed.

when i try to store chinese character using form submit it's storing successfully, if i try to store through ajax i am getting weird characters in the database.

in the ajax page i have added this line:

header("Content-type: text/html; charset=utf-8");

and in the html page added the below line:

<meta http-equiv="Content-type" value="text/html; charset=utf-8">

i have gone through many stack overflow suggestions but no luck.

please advice me on how to solve this.

Thanks in advance.

Code:HTML Code.

<html>
<head>
<meta http-equiv="Content-type" value="text/html; charset=utf-8">
<title>Test</title>
<script src="jquery.min.js"></script>
<script>
function addForm()
{
var english=document.getElementById('txt_english').value;
var id=document.getElementById('txt_id').value;
var chinese=document.getElementById('txt_chinese').value;
$.ajax(
{
    type : "POST",
    async: false,
    url :"ajax/ajax_add_form.php",
    data :
    {
    english:english,
    chinese:chinese,
    id:id
    }
}).done(
function(html)
{
        alert(html);

});
}
</script>
</head>
<body>
<input type='text' name='txt_id' id='txt_id' value='' /><br>
<input type='text' name='txt_english' id='txt_english' value='' />                          
<input type='text' name='txt_chinese' id='txt_chinese' value='' /> 
<button type="button" onclick="addForm()">Click Me!</button> 
</body>
</html>

PHP Code: ajax/ajax_add_form.php

<?php
header("Content-type: text/html; charset=utf-8");
include("../config.php");
extract($_REQUEST);
$sql=oci_parse($conn,"insert into test(id,english,chinese)values('".$id."','".$english."','".$chinese."')");
oci_execute($sql);
echo "success";
?>
Archana Palani
  • 247
  • 1
  • 6
  • 23
  • @Alvaro Gonzalez i have gone through this kind solution's before posting my question , here my question is slightly different , please go through again, i am using oracle 11G with AL32UTF8 characterset , which cannot be changed because data's not only coming from web application also coming from other tools like agile to the same database, hence with existing AL32UTF8 characterset i need to store chinese character set. , please advice me to solve or unblock my question hence other's can help me. – Archana Palani Aug 11 '16 at 02:44
  • `AL32UTF8` is the Oracle keyword for UTF-8 and UTF-8 can store the complete Unicode catalogue. You don't need to do any conversion. But I didn't feel you had an Oracle specific issue since you were adding meta tags to your HTML :-? – Álvaro González Aug 11 '16 at 06:09
  • @ÁlvaroGonzález yes , UTF8 can support multiple language, in my case i am getting issue only when go through ajax concept.if i change my character set from AL32UTF8 to WE8ISO8859P1 then i am not getting any issue, so how to store chinese character through ajax page with AL32UTF8 characterset. – Archana Palani Aug 11 '16 at 11:21
  • Sorry if I didn't explain myself correctly. Your Oracle will handle UTF-8 just fine. Everything so far suggests that your application is either not using UTF-8 at all or it isn't using it properly. As such, the question is unrelated to Oracle and a duplicate of the linked one. (AJAX mandates UTF-8, if you obtain ISO-8859-1 it's because you're actively converting data). – Álvaro González Aug 11 '16 at 11:28
  • @ÁlvaroGonzález , hi , i have tried various way but still i am not able to solve it , can you please check my code and correct me or can you send any example code storing chinese character through ajax page. – Archana Palani Aug 17 '16 at 03:33
  • @ÁlvaroGonzález , even though its storing some other character in database when i display in web page it's showing properly.my problem is some other tool like agile is also taking fetching that data there its showing whatever it stored in bad format. – Archana Palani Aug 19 '16 at 04:14
  • The linked question provides all the information you need. If I copy it here it won't be readable. – Álvaro González Aug 19 '16 at 07:17

0 Answers0