本文介绍了使用Ajax将中文字符存储在Oracle中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用ajax概念将html页面中的汉字存储到oracle数据库中.

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特性:

NLS_LANGUAGE = AMERICA
NLS_CHARACTERSET = WE8MSWIN1252
NLS_NCHAR_CHARACTERSET = AL16UTF16

当我尝试使用表单提交存储汉字时,它成功存储了,如果我尝试通过ajax存储,则数据库中出现了奇怪的字符.

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.

在ajax页面中,我添加了以下行:

In the ajax page I have added this line:

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

并在html页面中添加了以下行:

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.

谢谢.

代码: HTML代码.

<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代码: 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,chinese1)values(:id,:english,:chinese)");
oci_bind_by_name($sql, ':id', $id); 
oci_bind_by_name($sql, ':english', $english); 
oci_bind_by_name($sql, ':chinese', $chinese);
oci_execute($sql);
echo "success";
?>

我的问题:

即使当我回到网页时它以另一种格式存储时,它的工作原理并正确显示.

Even though it stores in another format when i get back in web page its working and displays correctly.

我的问题是另一种称为敏捷的工具也正在访问相同的数据,因此不会进行转换,它会显示数据库中存储的数据格式.

My problem is another tool called agile is also accessing the same data , hence there conversion is not happening it displays what ever data format is stored in database.

因此,我想完全按照用户输入的内容进行存储,而无需进行任何转换.

Hence i want to store exactly as user enters , no need of any conversion.

推荐答案

尝试

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

代替

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

这篇关于使用Ajax将中文字符存储在Oracle中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 09:41