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